Blogger Information
Blog 40
fans 0
comment 0
visits 29546
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
循环语句、对象自变量--2019-05-06
小人物的博客
Original
1085 people have browsed it
  1. 写一个while循环, 输出一个数值数组所有的奇数

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>0506作业</title>
</head>
<body>
<script>
    // 1. 写一个while循环, 输出一个数值数组所有的奇数-->
    var num= [1,2,3,4,5,6,7,8,9,10];
    document.write('数组内容:'+num+"</br>");
    document.write('其中奇数:');
    var k ;
    for (k in num) {
        if (num[k] % 2 !== 0) {
            document.write(num[k] +"," );
        }
        k++
    }
    document.write("</br>");
 
</script>



</body>
</html>

运行实例 »

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

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

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>0506作业</title>
</head>
<body>
<script>

    <!--2. 写一个对象字面量, 描述一款你喜欢的手机信息-->
    var myphone = {
        name:'Apple iPhone X (A1865) 64GB',
        color:'银色',
        screen:'5.8英寸',
        memory:'64GB',
        money:5999
    };

    document.write('商品名称:'+myphone.name+'</br>')
    document.write('商品颜色:'+myphone.color+'</br>')
    document.write('屏幕大小:'+myphone.screen+'</br>')
    document.write('商品价格:'+myphone.money+'</br>')

    document.write("</br>");


</body>
</html>

运行实例 »

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

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

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>0506作业</title>
</head>
<body>
<script>

    // <!--3. 写一个函数表达式, 计算三个数之和-->
    var i=123,j=234,p=345;
    var count =function() {
        return i+j+p;

    };
    document.write('合计结果:'+count(i,j,k));


</script>

</body>
</html>

运行实例 »

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

通过今晚的课程学习,了解以下内容:

循环语句

      for (初始变量,循环条件,更新条件)  {循环体}

      while  (条件) {循环体};  //入口判断,条件不成立时不执行循环体

      do {循环体}  while (条件);  //出口判断,先执行一次再判断,最少要至行一次

对象

   对象字面量

对象成员=属性+方法

属性:与变量的作用相同

方法:与函数的作用相同

     var user = {

          name:'pete',

        age:30,

        gender:'male'

}


Correction status:Uncorrected

Teacher's comments:
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