实例 1制作一个成绩判断
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>javascript第一节课</title> </head> <body> <script type="text/javascript"> var grade=80; if (grade>=90&&grade<=100) { alert('优秀'); }else if (grade>=80&&grade<=89) { alert('良好'); }else if (grade>=70&&grade<=79){ alert('良'); }else if (grade>=60&&grade<=69){ alert('及格'); }else if(grade<=59){ alert('不及格'); } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例 判断闰年还是平年
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>javascript第一节课</title> </head> <body> <script type="text/javascript"> var year=1888; if (year%100 !==0&&year%400==0||year%4==0) { alert('闰年'); }else{ alert('平年'); } //也可以用一下方式计算 // var year = 2020; // var isRun = year%4 == 0 && year%100 != 0 || year%400 ==0; // console.log(isRun); // if (isRun=true) { // alert('闰年'); // }else{ // alert('平年'); // } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例