30 <= a < 80
は正しい式ではありません。
これが意味するのは 30 <= a
の結果と、それが 80 未満かをチェックしています。なので 30 <= a
が true(1) であろうとも、false(0) であろうとも、80 未満なので必ずこの if 文は通ってしまいます。
ただしくは
30 <= a && a < 80
です。
html
1<!DOCTYPE html>
2<html lang="ja">
3<head>
4 <meta charset="UTF-8">
5 <title>タイトル</title>
6</head>
7<body>
8<script>
9 (function () {
10 'use strict';
11
12 var a = 70;
13
14 var result = null;
15 if (a < 30) {
16 result = '補修';
17 } else if (30 <= a && a < 80) {
18 result = '合格';
19 } else {
20 result = '優';
21 }
22
23 document.write(result);
24 })();
25</script>
26</body>
27</html>
なお、一つ前の if 文で a < 30
をチェックしているので、省略して
html
1<!DOCTYPE html>
2<html lang="ja">
3<head>
4 <meta charset="UTF-8">
5 <title>タイトル</title>
6</head>
7<body>
8<script>
9 (function () {
10 'use strict';
11
12 var a = 70;
13
14 var result = null;
15 if (a < 30) {
16 result = '補修';
17 } else if (a < 80) {
18 result = '合格';
19 } else {
20 result = '優';
21 }
22
23 document.write(result);
24 })();
25</script>
26</body>
27</html>
と書けます。