<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 输出1-100
let i = 1
while (i <= 100) {
document.write(`这是第${i}个数 <br>`)
i++
}
for (let x = 1; x <= 100; x++) {
document.write(`这是第${x}个数 <br>`)
}
// 1-100的总和
let p = 1
let sum = 0
while (p <= 100) {
sum += p
p ++
}
document.write(`1-100的总和为:${sum} <br>`)
let sum1 = 0
for (let q = 1; q <= 100; q++) {
sum1 += q
}
document.write(`1-100的总和为:${sum1} <br>`)
// 1-100之间的偶数和
let w = 1
let sum2 = 0
while (w <= 100) {
if(w % 2 === 0){
sum2 += w
}
w ++
}
document.write(`1-100之间的偶数和为:${sum2} <br>`)
let sum3 = 0
for (let t = 1; t <= 100; t++) {
if(t % 2 === 0){
sum3 += t
}
}
document.write(`1-100之间的偶数和为:${sum3} <br>`)
// 1-100之间的奇数和
let sum4 = 0
for (let y = 1; y <= 100; y++) {
if(y % 2 !== 0){
sum4 += y
}
}
document.write(`1-100之间的奇数和为${sum4} <br>`)
let sum5 = 0
let t = 1
while (t <= 100) {
if(t % 2 !== 0){
sum5 += t
}
t ++
}
document.write(`1-100之间的奇数和为${sum5}`)
</script>
</body>
</html>
标签:输出,奇数,偶数,while,循环,let,100
From: https://blog.csdn.net/2301_81256766/article/details/142407934