Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>FIZZBUZZ GAME</title>
  <link href="https://fonts.googleapis.com/css?family=Oswald|Roboto+Condensed&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Ubuntu&display=swap" rel="stylesheet">
</head>

<body>

<div class="wrapper">
  <h1 class="title">FIZZBUZZ GAME</h1>
  <div class="text">
    <p class="text_inner">黄色いリボンに表示されている数字の次の数字を、以下の4つのボタンから選んで押してください。正解の場合、黄色いリボンに次の数字が表示されます。尚、3の倍数ではFIZZ、5の倍数ではBUZZ、3と5の倍数ではFIZZBUZZを選ぶものとします。</p>
  </div>
  <div class="inner" id="inner">
    <p class="now" id="now">1</p>
    <ul class="button_wrap">
      <li><input id="button1" class="button" name="button" type="button" value="2"></li>
      <li><input id="button2" class="button" name="button" type="button" value="FIZZ"></li>
      <li><input id="button3" class="button" name="button" type="button" value="BUZZ"></li>
      <li><input id="button4" class="button" name="button" type="button" value="FIZZBUZZ"></li>
    </ul>
  </div>
</div>

<div class="retry_button_wrapper">
  <button id="retry_button">Retry</button>
</div>

</body>

</html>

              
            
!

CSS

              
                html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sub, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, aside, section, article, figure {
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0;
  vertical-align: baseline;
}

button, input{
  background-color: transparent;
  border: none;
  cursor: pointer;
  outline: none;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  display: block;
}

@keyframes gameoverEffect{
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(0%);
  }
}

html{
  font-size: 62.5%;
  letter-spacing: 0.1em;
  color: #222;
}

body{
  font-family: 'Oswald', sans-serif;
  background-color: #bb551d;
  background-image: url("data:image/svg+xml,%3Csvg width='42' height='44' viewBox='0 0 42 44' xmlns='http://www.w3.org/2000/svg'%3E%3Cg id='Page-1' fill='none' fill-rule='evenodd'%3E%3Cg id='brick-wall' fill='%235e2405' fill-opacity='0.4'%3E%3Cpath d='M0 0h42v44H0V0zm1 1h40v20H1V1zM0 23h20v20H0V23zm22 0h20v20H22V23z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

input{
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border: none;
  outline: none;
  background: transparent;
}

.wrapper{
  padding-bottom: 20px;
  max-width: 500px;
  width: 100%;
  margin: 10px auto 0;
  background: #f1f1f1;
  box-shadow: 6px 7px 9px -6px rgba(102,41,10,1);
  box-sizing: border-box;
}

.inner{
  max-width: 430px;
  width: 90%;
  margin: 0 auto;
  overflow: hidden;
}

#inner.gameover{
  position: relative;
}

#inner.gameover:after{
  content: 'GAME OVER';
  background: repeating-linear-gradient(90deg, #5a5a5a 0px, #5a5a5a 5px, #333333 5px, #333333 10px);
  width: 100%;
  height: 100%;
  color: #eee;
  font-family: 'Ubuntu', sans-serif;
  font-size: 40px;
  font-weight: bold;
  text-align: center;
  position: absolute;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all .3s;
  transform: translateY(0);
  animation-name: gameoverEffect;
  animation-duration: 0.5s;
  animation-timing-function: linear;
  z-index: 2;
}

.title{
  font-size: 40px;
  line-height: 1.3;
  font-weight: bold;
  text-align: center;
  text-decoration: none;
  font-weight: bold;
  color: #ec2020;
  text-shadow: 0px 4px 2px rgba(0, 0, 0, 0.32), 0px 1px 0px #d62222, 0px 2px 0px #da1e1e, 0px 3px 0px #b41919;
}

.text{
  width: 90%;
  margin: 10px auto 0;
}

.text_inner{
  font-size: 12px;
  font-family: "Yu Gothic Medium", "游ゴシック Medium", "YuGothic", "游ゴシック体", "ヒラギノ角ゴ Pro", "Hiragino Kaku Gothic Pro", "メイリオ", 
  "Meiryo", sans-serif;
  color: #333;
  text-align: left;
  line-height: 1.3;
  padding: 0 10px 10px;
  box-sizing: border-box;
}

.now{
  width: 100%;
  height: 40px;
  line-height: 40px;
  color: #f1f1f1;
  font-size: 24px;
  font-weight: bold;
  font-family: 'Oswald', sans-serif;
  text-align: center;
  background: #ffbd24;
  padding: 0 30px;
  margin: 10px auto 0;
  box-sizing: border-box;
  display: inline-block;
  position: relative;
}

.now:before, .now:after{
  position: absolute;
  content: '';
  width: 0px;
  height: 0px;
  z-index: 1;
}

.now:before{
  top: 0;
  left: 0;
  border-width: 20px 0px 20px 15px;
  border-color: transparent transparent transparent #f1f1f1;
  border-style: solid;
}

.now:after{
  top: 0;
  right: 0;
  border-width: 20px 15px 20px 0px;
  border-color: transparent #f1f1f1 transparent transparent;
  border-style: solid;
}

.button_wrap{
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  list-style: none;
  font-size: 14px;
  padding-left: 0;
  margin-top: 10px;
  width: 210px;
  margin: 10px auto 0;
}

.button_wrap li{
  margin: 10px 10px 0 0;
  color: #fff;
  max-width: 100px;
  width: 100%;
}

.button_wrap li:nth-of-type(2n){
  margin-right: 0;
}

.button_wrap li input{
  font-size: 18px;
  font-weight: bold;
  font-family: 'Oswald', sans-serif;
  width: 100%;
  padding: 8px 10px;
  box-sizing: border-box;
  color: #125c11;
  background: #2eae2c;
  border-radius: 3px;
  border-bottom: solid 4px #279625;
  box-shadow: 0px 2px 2px #43e7514a;
  text-shadow: 1px 1px 1px rgba(185, 248, 103, 0.5);
  transition: all .3s;
  cursor: pointer;
}

.button_wrap li input:active{
  transform: translateY(4px);
  border-bottom: none;
  box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.2);
}

.retry_button_wrapper{
  max-width: 100px;
  width: 100%;
  margin: 0 auto 20px;
}

#retry_button{
  font-size: 18px;
  font-weight: bold;
  font-family: 'Oswald', sans-serif;
  width: 100%;
  padding: 8px 10px;
  box-sizing: border-box;
  color: #125c11;
  background: #2eae2c;
  border-radius: 3px;
  border-bottom: solid 4px #279625;
  box-shadow: 0px 2px 2px #43e7514a;
  text-shadow: 1px 1px 1px rgba(185, 248, 103, 0.5);
  transition: all .3s;
  cursor: pointer;
  margin: 10px auto 0;
  display: none;
}

#retry_button.isShow{
  display: block;
}
              
            
!

JS

              
                const $btn = document.querySelectorAll('.button'); //ボタン
const $btn1 = document.querySelector('#button1'); //ボタン1
const $now = document.querySelector('#now'); //現在のID
const $inner = document.querySelector('#inner'); //gameover付与
const $retry_button = document.querySelector('#retry_button'); //ボタン

$retry_button.addEventListener('click', function () {
  //location.reload();
  location.href = '';
});

for (let i in $btn) {
  const $current_btn = $btn[i];

  $current_btn.onclick = function (params) {
    const $self = this;
    let self_value = $self.value; //クリックしたボタンの値
    let now_value = parseInt($now.textContent) + 1; //次の数値

    if (!isNaN(self_value)) {
      self_value = parseInt(self_value);
    }

    //選択した答えの判定
    answer(self_value, now_value);
  };
}

//選択した答えを受け取って、判定する
function answer(self_val, ans_val) {
  let answer = fizz_buzz(ans_val);

  if (self_val === answer) {
    $now.textContent = ans_val;
    ans_val++;
    $btn1.value = ans_val;
  }
  else {
    $inner.classList.add('gameover');
    $retry_button.classList.add('isShow');
  }
}

//FIZZBUZZの判定結果を返す
function fizz_buzz(num) {
  if ((num % 3) === 0 && (num % 5) === 0) {
    return 'FIZZBUZZ';
  }
  else if ((num % 3) === 0) {
    return 'FIZZ';
  }
  else if ((num % 5) === 0) {
    return 'BUZZ';
  }
  else {
    return num;
  }
}

              
            
!
999px

Console