12月16号作业
1、javascript变量、函数的定义
var num1 = 30;/变量声明/
function myFunction(a, b) {
函数的定义
}
alert(num1)//输出
2、javascript流程控制if else switch
<script type="text/javascript">
var num1 = 30;/变量声明/
var num2 = 6;
var score=60;
var myscore=90;
if(myscore>90){
alert(‘优秀’);
}else if(myscore<=90 && myscore>70){
alert(‘一般’);
}else if(myscore<=70 && myscore>60){
alert(‘及格’);
}
else{
alert(’不及格’);
}
var myscore=90;
switch(myscore){
case myscore>90:
alert(‘优秀’);
break;
case myscore<=90 && myscore>70:
alert(‘一般’);
break;
case myscore<=70 && myscore>60:
alert(‘及格’);
break;
}
</script>
3、javascript三种循环
for (i = 0; i < cars.length; i++) {
text += cars[i] + “<br>“;
}
<script type="text/javascript">
var i = 1;
var result = 0;
while(i<=100){
result=result+i;
i++;
}
alert(result);
</script>
<script type="text/javascript">
var i = 0;
var result = 0;
do{ i++;
result=result+i;
}while(i<100)
alert(result);
</script>
4、数据类型转换:parseInt、isNaN函数的使用
var a='12';
alert(parseInt(a));//字符串转数字
if isNaN(a){
alert('转换失败')
}