2018-09-17作业

1). 0-100的奇数和
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>循环语句</title>
<script type="text/javascript">

var Sum=0;
for(var i=1;i<=100;i++)
{
if(i%2 !==0)
{
Sum+=i;
}
}
alert("100以内的奇数和:"+Sum);

</script>
</head>
<body>

</body>
</html>

奇数.PNG
  1. 1-100以内的7的倍数

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">

var num=0;
var count=0;
for(var i=1;i<=100;i++)
{
if(i%7 ==0)
{
num +=i;
count++
}
}
alert('7的倍数的和' +num)
alert('0-100以内7的个数' +count)
</script>
</head>
<body>

</body>
</html>

7.1.PNG
7.PNG

3). 九九乘法表

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>123</title>
<script type="text/javascript">

        for(var row=1;row<=9;row++){
        for(var col=1; col<row+1;col++){
        var a=row*col;
        document.write(col+"*"+row+"="+a+""+"");
        }
        document.write(" ");
        document.write("<br/>");
        }

</script>
</head>
<body>
</body>
</html>

99.PNG

4). 0-100以内的所有质数
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>所有质数</title>
<script type="text/javascript">
var num = []
for(var i=2; i<=100;i++){
var count=1;
for(var j=2; j<parseInt(i/2);j++){
if(i%j==0){
count = 0;
break;
}
}
if(i>2&&count==1){
num.push(i)
} }
alert(num)
</script>
</head>
<body>
</body>
</html>

质数.PNG

5).

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
var num1 = prompt("请输入一个数字:")
var num2 = prompt("请输入一个数字:")
var num3 = prompt("请输入一个数字:")
if(num1<num2 && num1<num3){
if(num2<num3){
alert(num1+","+num2+","+num3);
}
else{ alert(num1+","+num3+","+num2);
}
}
else if(num2<num1 &&num2<num3){
if(num1<num3){
alert(num2+","+num1+","+num3)
}
else{
alert(num2+","+num3+","+num1);
}
}
else{
if(num1<num2)
{
alert(num3+","+num1+","+num2);
}
else{
alert(num3+","+num2+","+num1);
}
}

</script>
</head>
<body>

</body>
</html>

练习6.PNG

6).水仙花数

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
var num1 = prompt("请输入一个数字:")
var num2 = prompt("请输入一个数字:")
var num3 = prompt("请输入一个数字:")
if(num1<num2 && num1<num3){
if(num2<num3){
alert(num1+","+num2+","+num3);
}
else{ alert(num1+","+num3+","+num2);
}
}
else if(num2<num1 &&num2<num3){
if(num1<num3){
alert(num2+","+num1+","+num3)
}
else{
alert(num2+","+num3+","+num1);
}
}
else{
if(num1<num2)
{
alert(num3+","+num1+","+num2);
}
else{
alert(num3+","+num2+","+num1);
}
}

</script>
</head>
<body>

</body>

</html>
01.PNG
02.PNG
03.PNG
04.PNG

推荐阅读更多精彩内容