0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【JavaScript】1から100までの間で、3の倍数(3〜99)の数だけを足した合計値を表示せよ

Last updated at Posted at 2021-05-06
<!DOCTYPE html>
<html lang="ja">
<head>
   <meta charset="UTF-8">
   <title>1から100までの間で3の倍数の数だけを足した合計値</title>
</head>
<body>
<script>
    var sum = 0; 
    for (var i = 1; i <= 100; i++) {
        if (i % 3 === 0) {
        document.write('<p>' +  sum + ' + ' + ''  + i + ''  + '</p>');
        sum = sum + i ; //sum += i でもOK
        document.write('<p>' + '= ' + sum + '<p>');
        }
    }
    document.write('<h1>' +  '合計:' + sum  + '<h1>');
</script>
</body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?