Blogger Information
Blog 61
fans 1
comment 0
visits 69767
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0506-用while循环打印数组中数值的非偶数
我的博客
Original
573 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>作业1</title>
    <script>
    var $user=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
var i=0;
while (i<$user.length) {            //循环开始,如果(i<$user的内容长度),也说明了循环的次数。
    if ($user[i] % 2 !==0){         //如果数组的元素%2,余数不等于0,说明他是奇数。
        console.log($user[i]);      //在控制台输出数组中不包含偶数的元素。
        document.write($user[i]+ '<br/>') //在网页输出不包含数组元素偶数的数值。
    }
    
    i++;                                //每运行一次 i+1 

}
</script>
</head>
<body>
    
</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