<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>while练习</title>
<script type="text/javascript">
/*
假如投资的年利率为5%,试求从1000块增长到5000块,需要花费多少年
*/
var money = 1000;
var year = 0;
while(money < 5000){
money = money*1.05;
year++;
}
console.log("需要花费"+year+"年");
</script>
</head>
<body>
</body>
</html>
03-30
3383
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-18
3616
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-29
5591
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-02
831
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)