-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1005-if-else.html
73 lines (65 loc) · 1.67 KB
/
day1005-if-else.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!doctype html>
<html lang="zh-Hans">
<head>
<meta charset="utf-8">
<meta name="keywords" content="JavaScript,if,else">
<meta name="description" content="JavaScript 条件控制语句">
<title>JavaScript 条件控制语句</title>
<script>
// 求两个数的最大数
var max, a = 10, b = 13;
if (a > b) {
max = a;
} else {
max = b;
}
console.log(a, b, '较大的数是' + max);
// 判断一个数是偶数还是奇数
var x = 111;
if (x % 2 === 0) {
console.log(x + '是偶数');
} else {
console.log(x + '是奇数');
}
// 分数转换
var grade = 'E', score = 55;
if (score >= 90) {
grade = 'A';
} else if (score >= 80) {
grade = 'B';
} else if (score >= 70) {
grade = 'C';
} else if (score >= 60) {
grade = 'D';
}
console.log(score + '分是' + grade);
// 判断四季
var season = '冬', nthMonth = 1;
if (3 <= nthMonth && nthMonth <= 5) {
season = '春';
} else if (6 <= nthMonth && nthMonth <= 8) {
season = '夏';
} else if (9 <= nthMonth && nthMonth <= 11) {
season = '秋';
}
console.log(nthMonth + '月是' + season + '季');
// 判断一个人的年龄是否满18岁
var age = 19;
if (age >= 18) {
console.log(age + '岁是成年');
} else {
console.log(age + '岁是未成年');
}
// 判断一个年份是闰年还是平年
var year = 2000;
if ((year % 4 === 0 && year % 100 !== 0)
|| (year % 400 === 0)) {
console.log(year + '年是闰年');
} else {
console.log(year + '年不是闰年');
}
</script>
</head>
<body>
</body>
</html>