Help us understand the problem. What is going on with this article?

JavaScriptで勉強時間を伸ばすボタン作ってみた!

休憩したくなったら押すだけです!

永遠と「休憩」がでなければ、ひたすら勉強できますよ笑

Screen Recording 2020-11-22 at 03.46 PM.gif

index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <title>GAME</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>押してね!</h1>
    <div id="btn">?</div>
    <script src="js/main.js"></script>
  </body>
</html>
styles.css
h1 {
  text-align: center;
}

body {
  background: #efefef;
}

#btn {
  width: 200px;
  height: 200px;
  background: #ef454a;
  border-radius: 30%;
  margin: 30px auto;
  text-align: center;
  line-height: 200px;
  color: white;
  font-weight: bold;
  font-size: 42px;
  cursor: pointer;
  box-shadow: 0 10px 0 #d1483e;
  user-select: none;
}

#btn:hover {
  opacity: 0.9;
}

#btn:active {
  box-shadow: 0 5px 0 #d1483e;
  margin-top: 40px;
}
main.js
'use strict';

{
  const btn = document.getElementById('btn');
 
  btn.addEventListener('click', () => {
    const n = Math.floor(Math.random() * 3);

    switch (n) {
      case 0:
        btn.textContent = '休憩';
        break;
      case 1:
        btn.textContent = 'もう10分';
        break;
      case 2:
        btn.textContent = 'もう15分';
        break;
    }
  })
}

JavaScriptほんと楽しい(^^)

参考

JavaScriptでおみくじを作ろう

engineer_kazuki
Webエンジニアを目指してアウトプットしています。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away