Blogger Information
Blog 20
fans 0
comment 0
visits 13733
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第10章 JS中的循环,对象与函数——2019年5月06日22:00
KA的博客
Original
782 people have browsed it

5月6日作业

  1. 写一个while循环, 输出一个数值数组所有的奇数



实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>求奇数偶数之和</title>
</head>
<body>
	
	
	
	<script>
	   //while
	   var i=0;
	   var sum1=0;
	   var sum2=0;
       while(i<=10){
       	if(i%2!==0){
       		sum1+=i;
            i++;
       	}else{
       		sum2+=i;
       		i++;
       	};
       	  
       }
       document.write("while循环得到的奇数之和为"+sum1+","+"偶数之和为"+sum2)+"</br>";

       //for计算奇数之和
       var sum3=0;
   
       for(var j=0;j<=10;j++){
         if(j%2!==0){
             sum3+=j;
         }
       };
       document.write("</br>"+"for循环得到的奇数之和为"+sum3);

       //do while计算偶数之和
       var sum4=0;
       var k=0;	
       do{
         if(k%2==0){
            sum4+=k;
            

         }
         	k++;
         
       }while(k<=10);
       document.write("</br>"+"do ...while循环得到的偶数之和为"+sum4);

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

运行实例 »

点击 "运行实例" 按钮查看在线实例





2. 写一个对象字面量, 描述一款你喜欢的手机信息

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>对象字面量</title>
</head>
<body>
    <h1>对象字面量</h1>
	<script>
        var iphoneX ={
        	name:'iphoneX',
        	price:'5999',
        	Year:'2019',

        };
        iphoneX['name'];
        iphoneX.price;
	</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例



3. 写一个函数表达式, 计算三个数之和



5月6日作业

1. 写一个while循环, 输出一个数值数组所有的奇数
2. 写一个对象字面量, 描述一款你喜欢的手机信息
3. 写一个函数表达式, 计算三个数之和


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post