<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>向页面输出100以内的偶数</title>
</head>
<body>
<script>
for(i = 1 ; i <= 100 ; i++){
if( i % 2 ===0)
document.write(`${i}`)
}
// 方法二:
// for (let i = 0; i <=100; i++){
// if ((i + 1) % 2 === 0){
// document.write(`${i+1}`)
// }
// }
// 方法三:
// for(i = 0 ; i < 100 ;){
// i+=2
// document.write(`${i}`)
// }
</script>
</body>
</html>
核心思路:
1. i % 2 === 0 ,i除2,取余为零
2.不要忘记写 i++ !