Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Sum of odd Fibonacci numbers JS

  //sum-all-odd-fibonacci-numbers-in-js
function (num) {
	let a = 1;
	let b = 1;
	let sum = 1;
	while(b <= num){
		if(b % 2 == 1){
			sum += b;
		}
	let temp = b;
	b = a + b;
	a = temp;
}
if(sum ==2){
	return "Number";
}
return sum;
}
 
PREVIOUS NEXT
Tagged: #Sum #odd #Fibonacci #numbers #JS
ADD COMMENT
Topic
Name
6+8 =