1.求1000以内所有不能被7整除的整数的和
<script type="text/javascript">
var n=1;
var sum=0,count=0;
while(n<=1000){
if(n%7!=0){
sum=sum+n;
count++;
}
n++
}
document.write(sum+"<br />");
document.write(count);
</script>
2.斐波那契数列
<title></title>
<script type="text/javascript">
var a=0;
var b=1;
var count=1
document.write(b+",");
while (count<=20){
c=a+b;
a=b;
document.write(b+"/"+c+",");
b=c;
sum=a+b+c;
count++;
}
</script>
3.求任意个整数的和
<script type="text/javascript">
var time=prompt("您要输入多少个整数?");
var count=1
var sum=0
while (count<=time){
var num=parseInt(prompt("请输入整数"));
sum+=num;
count++;
}
document.write(sum);
</script>
4.猜数游戏
<script type="text/javascript">
do{
var num=prompt("请输入一个数字");
if (num==7) {
alert("输入正确");
}else if(num<7){
alert("小啦");
}else if(num>7){
alert("大啦");
}else{
alert("输错啦")
}
}while(num!=7)
</script>