-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay71.js
More file actions
21 lines (16 loc) · 664 Bytes
/
Day71.js
File metadata and controls
21 lines (16 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//* generates the Fibonacci series up to a specified number and calculates their sum:
function fibonacciSeries(n) {
let fibSeries = [0, 1];
let sum = 1; // Sum starts with 1 because the series starts with 0, 1
for (let i = 2; i <= n; i++) {
fibSeries[i] = fibSeries[i - 1] + fibSeries[i - 2];
sum += fibSeries[i];
}
return { series: fibSeries, sum: sum };
}
// Example usage:
const n = 10; // Change this number to generate Fibonacci series up to n
const result = fibonacciSeries(n);
console.log(`Fibonacci Series up to ${n}:`);
console.log(result.series);
console.log(`Sum of Fibonacci Series up to ${n}: ${result.sum}`);