<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>1から100までの間で、3の倍数の数だけを足した合計値</title>
</head>
<body>
<script>
var sum = 0; //初期値0
for (var i = 1; i <= 100; i++) {
if (i%3 === 0) {
sum = sum + i ; //sum += i でもOK
}
}
document.write(sum);
</script>
</body>
</html>
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme