0% found this document useful (0 votes)
36 views

Fib Js

The first document (fib.js) prompts the user to enter a value for n, then defines initial values for variables n1 and n2. It uses a for loop to calculate subsequent Fibonacci numbers up to the input value of n, outputting each new number and updating n1 and n2. The second document (sq.js) similarly prompts for a value of n, then uses a for loop to output each number from 1 to n and its square, calculating the square inside the loop.

Uploaded by

sansayana
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Fib Js

The first document (fib.js) prompts the user to enter a value for n, then defines initial values for variables n1 and n2. It uses a for loop to calculate subsequent Fibonacci numbers up to the input value of n, outputting each new number and updating n1 and n2. The second document (sq.js) similarly prompts for a value of n, then uses a for loop to output each number from 1 to n and its square, calculating the square inside the loop.

Uploaded by

sansayana
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

fib.js var n = prompt(what is the value of n?

\n, ); var n1=0; var n2=1; alert(first number is: + n1 + \n); alert(Second number is: + n2 + \n); for(i=3;i<=n;i++) { var m1=n1+n2; alert( + m1 + \n); n1 = n2; n2 = m1; } sq.js var n = prompt(what is the value of n?, ); var square; document.writeln('<pre>'); for (var i=1; i<n; i++) { // multiple instruction must be between document.write(i); // `{ .... }' square = i*i; document.writeln (' squared is ', square); }

You might also like