将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>
运行实例 »
点击 "运行实例" 按钮查看在线实例