feat(curriculum): add odd Fibonacci sum calc challenge lab (#62271)

This commit is contained in:
Hillary Nyakundi
2025-09-25 10:48:52 +03:00
committed by GitHub
parent 945be2126f
commit c29dc53f1a
5 changed files with 120 additions and 0 deletions
+6
View File
@@ -3497,6 +3497,12 @@
"In this lab, you will convert special characters in a string to their corresponding HTML entities."
]
},
"lab-odd-fibonacci-sum-calculator": {
"title": "Build an Odd Fibonacci Sum Calculator",
"intro": [
"In this lab you will build an odd Fibonacci sum calculator that takes a number and returns the sum of all odd Fibonacci numbers that are less than or equal to that number."
]
},
"lab-optional-arguments-sum-function": {
"title": "Build an Optional Arguments Sum Function",
"intro": [
@@ -0,0 +1,9 @@
---
title: Introduction to the Build an Odd Fibonacci Sum Calculator
block: lab-odd-fibonacci-sum-calculator
superBlock: full-stack-developer
---
## Introduction to the Build an Odd Fibonacci Sum Calculator
In this lab you will build an odd Fibonacci sum calculator that computes the sum of all odd Fibonacci numbers that are less than or equal to a given positive integer.
@@ -0,0 +1,89 @@
---
id: a5229172f011153519423690
title: Build an Odd Fibonacci Sum Calculator
challengeType: 26
dashedName: build-an-odd-fibonacci-sum-calculator
---
# --description--
In this lab you will build an odd Fibonacci sum calculator that computes the sum of all odd Fibonacci numbers that are less than or equal to a given positive integer.
**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories**
1. You should have a `sumFibs` function that accepts a number as an argument.
1. The `sumFibs` function should return the sum of all odd Fibonacci numbers that are less than or equal to the given number.
1. The Fibonacci sequence starts with `0` and `1`, and each subsequent number is the sum of the two previous ones.
1. Only the odd Fibonacci numbers should be added to the sum.
# --hints--
You should have a `sumFibs` function.
```js
assert.isFunction(sumFibs);
```
`sumFibs(1)` should return a number.
```js
assert.isNumber(sumFibs(1));
```
`sumFibs(1000)` should return `1785`.
```js
assert.strictEqual(sumFibs(1000), 1785);
```
`sumFibs(4000000)` should return `4613732`.
```js
assert.strictEqual(sumFibs(4000000), 4613732);
```
`sumFibs(4)` should return `5`.
```js
assert.strictEqual(sumFibs(4), 5);
```
`sumFibs(75024)` should return `60696`.
```js
assert.strictEqual(sumFibs(75024), 60696);
```
`sumFibs(75025)` should return `135721`.
```js
assert.strictEqual(sumFibs(75025), 135721);
```
# --seed--
## --seed-contents--
```js
```
# --solutions--
```js
function sumFibs(num) {
let a = 0, b = 1;
let sum = 0;
while (b <= num) {
if (b % 2 !== 0) {
sum += b;
}
[a, b] = [b, a + b];
}
return sum;
}
```
@@ -0,0 +1,15 @@
{
"name": "Build an Odd Fibonacci Sum Calculator",
"isUpcomingChange": false,
"dashedName": "lab-odd-fibonacci-sum-calculator",
"helpCategory": "JavaScript",
"blockLayout": "link",
"blockType": "lab",
"usesMultifileEditor": true,
"challengeOrder": [
{
"id": "a5229172f011153519423690",
"title": "Build an Odd Fibonacci Sum Calculator"
}
]
}
@@ -392,6 +392,7 @@
"lab-sum-all-numbers-algorithm",
"lab-dna-pair-generator",
"lab-html-entitiy-converter",
"lab-odd-fibonacci-sum-calculator",
"lab-optional-arguments-sum-function",
"review-javascript-fundamentals",
"quiz-javascript-fundamentals"