Blogger Information
Blog 63
fans 1
comment 0
visits 76097
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript 循环、变量和函数
桃儿的博客
Original
754 people have browsed it

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

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

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


实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript 循环、变量和函数</title>
</head>
<body>
<script>
// 1. 写一个while循环, 输出一个数值数组所有的奇数
var numbers1=[11,12,13,14,15,16,21,22,23,24,25,26];
var i=0;
while (i<numbers1.length){
    // console.log(numbers1[i]);
    if(numbers1[i] %2 != 0){
        console.log(numbers1[i]);
    }
    i+=1;
}
// 2. 写一个对象字面量, 描述一款你喜欢的手机信息
// 对象字面量使用一对大括号创建
var mobile={
    brand:'HONOR',
    model:'荣耀20',
    size:'6.1寸',
    processor:'麒麟980'
};
console.log(mobile);
// 对象使用点语法('.'),访问其内部成员
// var mobile2={};
// mobile2.brand='HONOR';
// mobile2.model='荣耀20';
// mobile2.size='6.1寸';
// mobile2.processor='麒麟980';
// console.log(mobile2.brand+mobile2.model+mobile2.size+mobile2.processor);

// 3. 写一个函数表达式, 计算三个数之和
var add=function(x,y,z) {
    return x+y+z;
}
console.log(add(20,55,80));

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

运行实例 »

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


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