LoginSignup
0
0

More than 1 year has passed since last update.

【JavaScript】1+2+3+…と1ずつ加算し、【和】が1000を超えた時までの加算値と、合計値を表示せよ。

Last updated at Posted at 2021-05-06
<!DOCTYPE html>
<html lang="ja">
<head>
   <meta charset="UTF-8">
   <title>1+2+3+と足される数を1ずつ増やしながら足していき和が1000を超えるときの足される数値と合計値を表示してください</title>
</head>
<body>
  <!-- 1+2+3+と足される数を1ずつ増やしながら足していき
    和が1000を超えるときの足される数値と合計値を表示してください -->
<script>
        var sum = 0; 
        var i = 0;
        while (sum <= 1000) {
            i++;
            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
4

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