当前,您的代码中有两种错别字,它们会打乱语法,从而导致您的代码无法按预期工作:
// You had a period here instead of a comma (after "k=0"), which will cause
// the remainder of your for loop to not be properly parsed
for (i = 0, j = 1, k = 0, fib = 0; i < 50; i++, fib = j + k, j = k, k = fib) { ... }
和:
// This was previously document.write("<br>";), note the transposed ";)" which should be
// ");"
document.write("<br>";)
例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>js book example1</title> </head> <body> <p>test</p> <script> document.write("<h2>Table of Fibonacci Numbers</h2>"); for (i = 0, j = 1, k = 0, fib = 0; i < 50; i++, fib = j + k, j = k, k = fib) { document.write("Fibonacci(" + i + ") =" + fib); document.write("<br>"); } </script> </body> </html>