1.
八折
var price = parseInt(prompt('输入价格'))alert(price * .8)
2.
3次方
function three_power(N) {return Math.pow(N, 3)
}
var N = parseInt(prompt('输入N'))
var ret = three_power(N)
alert(ret)
3.
递归的fibonacci
function fib(N) {if (N === 1 || N === 2) {
return 1
}
return fib(N-1) + fib(N-2)
}
var N = parseInt(prompt('输入N'))
var ret = fib(N)
alert(ret)
4.
非递归的fibonacci
function fib(N) {if (N === 1 || N === 2) {
return 1
}
var farr = [1, 1], n
for (var i=2 i < N ++i) {
n = 0
n = farr[i - 1] + farr[i - 2]
farr.push(n)
}
return farr[N-1]
}
var N = parseInt(prompt('输入N'))
var ret = fib(N)
alert(ret)
<script>for(var i=1i<=6i++)
document.write("<h"+i+">示例文字标题"+"</h"+i+"><br />")
</script>