LoginSignup
0
0

More than 1 year has passed since last update.

【JavaScript】繰り返し処理を利用し、西暦2000年から本日までの西暦の年のみを全て表示

Last updated at Posted at 2021-05-07
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>2000年から本日までの年だけを全て表示</title>
</head>
<body>
    <script>
        document.write('<p>' + '↓現在日時分秒を取得(new Dateメソッド)' + '</p>') // ←任意行
        var date = new Date();   
        document.write('<p>' + date + '</p>')                               // ←任意行
        document.write('<p>' + '↓現在日時から「年」のみを取得(getFullYeaメソッド)' + '</p>') // ←任意行
        var year = date.getFullYear(); 
        document.write('<p>' + year +'がyaerに入る' + '</p>') // ←任意行
        document.write('<p>' + '↓初期値を設定' + '</p>')      // ←任意行
        for (var i = 2000; i<= year; i++) {
        document.write('<p>' + i + '</p>')
        }
    </script>
</body>
</html>

image.png

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