Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fibonacci sequence in javascript using for loop

let fibonacci = [0, 1]; // set initial conditions

for (let i = 2; i < 10; ++i) {
    // add the two previous elements to get the current element
    fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1];
}

console.log(fibonacci); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript int max 
Javascript :: jquery check a radio button 
Javascript :: javascript function to generate random alphanumeric string 
Javascript :: open link in new tab jquery 
Javascript :: copy text to clipboard javascript 
Javascript :: how to change background image url in javascript 
Javascript :: disable console log alert eslint 
Javascript :: javascript location href target _blank 
Javascript :: console.log big red text 
Javascript :: how to vibrate phone using javascript 
Javascript :: console.log ejs 
Javascript :: javascript format currency 
Javascript :: react bootstrap styles not working 
Javascript :: clone object in js 
Javascript :: get value from url 
Javascript :: javascript live time 
Javascript :: × MUI: makeStyles is not longer exported from @mui/material/styles. You have to import it from @mui/styles. 
Javascript :: js fetch delete 
Javascript :: javascript detect ios device 
Javascript :: javascript reduce function to get sum of object value 
Javascript :: connection refused xmlhttprequest 
Javascript :: how to delay iterations in javascript 
Javascript :: js stop form submit 
Javascript :: add jquery to project 
Javascript :: javascript replace all characters except letters and numbers 
Javascript :: js get first space in string 
Javascript :: npm react hook form 
Javascript :: add select option javascript 
Javascript :: skip mongoose 
Javascript :: set text of dom element 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =