<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<p>斐波那契数列:1,1,2,3,5,8,13,21,34,55,89,144........... </p>
<p>求斐波那契数列第n项的值</p>
</body>
<script type="text/javascript">
var n = prompt("请输入数字n")
var num1 = 1;
var num2 = 1;
for(var i = 3; i <= n; i++) {
var temp = num2;
num2 = num1 + num2;
num1 = temp;
}
alert(num2);
</script>
</html>
精心整理的学习笔记,希望对大家可以有所帮助额。如果对您有所帮助,请帮忙顶顶额。