hint [3/7]
To get the next number of the series, you need to add the current one to the previous and that will give you the next one.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/7]
To check if a number is even all you have to check is if that number % 2 == 0.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [5/7]
As you get the next odd one, don't forget to add it to a global variable that can be returned at the end. result += currNumber;
Will do the trick.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [6/7]
Solution ahead!
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [7/7]
function sumFibs(num) {
var prevNumber = 0;
var currNumber = 1;
var result = 0;
while (currNumber <= num) {
if (currNumber % 2 !== 0) {
result += currNumber;
}
currNumber += prevNumber;
prevNumber = currNumber - prevNumber;
}
return result;
}
If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @Rafase282 @d3ddd
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [1/8]
Make sure you've tried to hard to solve it yourself before proceeding. :construction:
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [1/8]
Make sure you've tried to hard to solve it yourself before proceeding. :construction:
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [2/8]
You will need to gather all the Fibonacci numbers and then check for the odd ones. Once you get the odd ones then you will add them all. The last number should be the number given as a parameter if it actually happens to be an off Fibonacci number.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [3/8]
To get the next number of the series, you need to add the current one to the previous and that will give you the next one.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/8]
To check if a number is even all you have to check is if that number % 2 == 0.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [5/8]
As you get the next odd one, don't forget to add it to a global variable that can be returned at the end. result += currNumber;
Will do the trick.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [6/8]
Solution ahead!
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [7/8]
function sumFibs(num) {
var prevNumber = 0;
var currNumber = 1;
var result = 0;
while (currNumber <= num) {
if (currNumber % 2 !== 0) {
result += currNumber;
}
currNumber += prevNumber;
prevNumber = currNumber - prevNumber;
}
return result;
}
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [8/8]
function sumFibs(num) {
// create an array of fib numbers till num
var arrFib = [1];
for (var i = 1; i <=num;) {
arrFib.push(i);
i = arrFib[arrFib.length - 1] + arrFib[arrFib.length - 2];
}
// return the sum of odd numbers from the array
var res = arrFib.reduce(function(prev, curr) {
if (curr%2 !== 0) return prev + curr;
else return prev;
});
return res;
}
If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @Rafase282 @d3ddd for your help with Bonfire: Sum All Odd Fibonacci Numbers
NOTE: Please add your username only if you have added any relevant main contents to the wiki page. (Please don't remove any existing usernames.)
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [1/8]
Make sure you've tried to hard to solve it yourself before proceeding. :construction:
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [2/8]
You will need to gather all the Fibonacci numbers and then check for the odd ones. Once you get the odd ones then you will add them all. The last number should be the number given as a parameter if it actually happens to be an off Fibonacci number.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [3/8]
To get the next number of the series, you need to add the current one to the previous and that will give you the next one.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/8]
To check if a number is even all you have to check is if that number % 2 == 0.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [5/8]
As you get the next odd one, don't forget to add it to a global variable that can be returned at the end. result += currNumber;
Will do the trick.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [1/8]
Make sure you've tried to hard to solve it yourself before proceeding. :construction:
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [2/8]
You will need to gather all the Fibonacci numbers and then check for the odd ones. Once you get the odd ones then you will add them all. The last number should be the number given as a parameter if it actually happens to be an off Fibonacci number.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [3/8]
To get the next number of the series, you need to add the current one to the previous and that will give you the next one.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/8]
To check if a number is even all you have to check is if that number % 2 == 0.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [5/8]
As you get the next odd one, don't forget to add it to a global variable that can be returned at the end. result += currNumber;
Will do the trick.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]