7、运算符
<script>
let num1 = 1
num1 += 1
console.log(num1);
let num2 = 2
console.log(num2++ + --num2 - ++num2 + --num2)
let a = 1
let b = "1"
console.log(a == b)
console.log(a === b)
console.log(true && false)
console.log(true || false)
console.log(!5)
</script>
8、分支语句
8.1 单分支语句
<script>
if ("") {
console.log("语句1");
}
if (" ") {
console.log("语句2");
}
</script>
8.2 双分支语句
<script>
let year = +prompt("输入年份")
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
alert(`${year}为润年`)
}
else {
alert(`${year}为平年`)
}
</script>
9、switch语句
<script>
num1 = +prompt("请输入第一个数字:")
num2 = +prompt("请输入第二个数字:")
a = prompt("请输入计算方式:")
switch (a) {
case "+":
alert(num1 + num2)
break
case "-":
alert(num1 - num2)
break
case "*":
alert(num1 * num2)
break
case "/":
if (num2 != 0)
alert(num1 / num2)
else
alert("被除数不能为0")
break
default:
break
}
</script>
10、循环结构
<script>
let num = 1
while (num <= 100) {
if (num == 8) {
num++
continue
}
if (num % 2 == 0) {
document.write(num + "--")
}
num++
}
</script>