Blogger Information
Blog 49
fans 1
comment 0
visits 45478
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
利用while循环输出数组里的奇数,用对象字面量来描述一款手机,用函数来求三个数值的和(学习并运用while循环,了解对象字面量,利用function求和)2019年5月6日20点
Nick的博客
Original
874 people have browsed it

将JavaScript代码写在<Script>标签中,利用while循环实现输出数组内所有奇数;用字面量输出一款手机的基本信息;设定function的参数值和函数体求和。

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript作业</title>
</head>
<body>
<script>
    // 100以内的奇数全部换行显示输出在页面上
    var  a = 0;
    while (a < 100){
        if(a % 2 == 1){
            // document.write(a + "<br>");
            document.write(a + ',');
        }
        a++;
    }

    // 输出一个换行br
    document.write( "<br>");

// 用对象字面量描述一款手机
    var phone = {
        model:'iphone X Max',
        soc:'A12',
        camera:'12.0 MP',
        storage:'256G',
        system:'ios',
        color:'red'
    }
    document.write('model:' + phone.model + "<br>");
    document.write('soc:' + phone.soc + "<br>");
    document.write('camera:' + phone.camera + "<br>");
    document.write('storage:' + phone.storage + "<br>");
    document.write('system:' + phone.system + "<br>");
    document.write('color:' + phone.color + "<br>");

    // 输出一个换行br
    document.write( "<br>");

    // var x = 50;
    // var y = 38;
    // var z = 18;
    // 用函数球三个值的和
    var sum = function (x,y,z){return x + y + z};
    document.write(sum(50, 38, 18));

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

运行实例 »

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


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