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>
  <head>
    <meta charset="UTF-8">
    <title>フォントかるた</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <!-- Webフォント -->
    <!-- https://fonts.google.com -->
    <link href="https://fonts.googleapis.com/css?family=Kosugi|Kosugi+Maru|M+PLUS+1p|M+PLUS+Rounded+1c|Noto+Sans+JP|Noto+Serif+JP|Sawarabi+Gothic|Sawarabi+Mincho&display=swap" rel="stylesheet">
    <!-- Bootstrap -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <!--
    <link type="text/css" href="style.css" rel="stylesheet" />
    <script type="text/javascript" src="index.js"></script>
    -->
  </head>
  <body>
    <class="toolbar">
      <div>お題:<span id="answer_font"></span><span id="opened_num"></span></div>
      <div><span id="now_result"></span></div>
    </div>
    <div>
      <!--
      <button class="btn btn-info" id="pass_button">パスする</button>
      -->
      <button class="btn btn-danger" id="restart_button">最初から</button>
    </div>
    <div>
      <input type="checkbox" id="shuffle">
      <label for="shuffle">シャッフルする</label>
    </div>
    <div class="row" id="play_area">
    </div>
  </body>
</html>

              
            
!

CSS

              
                /*
@font-face {
    font-family: フォント名;
    src: url(font/フォント名.ttf) format("truetype");
}
*/
.font1 {
  font-family: 'Noto Sans JP', sans-serif;
}
.font2 {
  font-family: 'Noto Serif JP', serif;
}
.font3 {
  font-family: 'M PLUS 1p', sans-serif;
}
.font4 {
  font-family: 'M PLUS Rounded 1c', sans-serif;
}
.font5 {
  font-family: 'Sawarabi Mincho', sans-serif;
}
.font6 {
  font-family: 'Sawarabi Gothic', sans-serif;
}
.font7 {
  font-family: 'Kosugi Maru', sans-serif;
}
.font8 {
  font-family: 'Kosugi', sans-serif;
}

div.card {
  border: solid 5px #06bd36;
}

              
            
!

JS

              
                $(document).ready(function () {
  const cardText = "愛のあるユニークで豊かな書体。";
  const fontNameData = {
    1: "Noto Sans JP",
    2: "Noto Serif JP",
    3: "M PLUS 1p",
    4: "M PLUS Rounded 1c",
    5: "Sawarabi Mincho",
    6: "Sawarabi Gothic",
    7: "Kosugi Maru",
    8: "Kosugi",
  };
  let openedFont = [];// Array
  let answer;
  let completeFlg = false;

  function rand(n) {
      return Math.floor(Math.random() * n) + 1;
  }

  // 初期化
  restart();

  // クリックしたら判定する(動的に生成する要素なので、documentにclickイベントを当てる)
  $(document).on("click", ".card", function (e) {
    console.log('card clicked');  
    if (completeFlg) {
      // コンプ済み
      return;
    }

    let clicked = $(e.currentTarget).attr("id");
    console.log(clicked);
    console.log(answer);

    if (clicked == answer) {
      $("#now_result").text("お見事!");
      open(e.currentTarget);
      if (openedFont.length == Object.keys(fontNameData).length) {
        complete();
      } else {
        next();
      }
    } else {
      $("#now_result").text("お手つき!");
    }
  });

  $("#pass_button").on("click", function (e) {
    pass();
  });

  $("#restart_button").on("click", function (e) {
    restart();
  });

  function restart() {
    console.log('restart() called');
    let cardHtml = "";
    openedFont = [];
    completeFlg = false;
    if ($("#shuffle").prop("checked")) {
      let selectId = 0;
      let selectedFont = [];// Array
      while (selectedFont.length != Object.keys(fontNameData).length) {
      console.log(selectedFont.length);
      console.log(Object.keys(fontNameData).length);
        while (1) {
          // まだ使ってないお題になるまでループ
          selectId = rand(Object.keys(fontNameData).length);
          if (selectedFont.indexOf(selectId) == -1) {
            cardHtml += '<div class="col-sm-3 p-1">';
            cardHtml += '<div class="card font' + selectId +'" id="' + selectId + '">';
            cardHtml += '<div class="card-body">';
            cardHtml += '<h5 class="text">' + cardText + '</h5>';
            cardHtml += '<p class="font_name">' + fontNameData[selectId] + '</p>';
            cardHtml += '</div>';
            cardHtml += '</div>';
            cardHtml += '</div>';

            selectedFont.push(selectId);
            break;
          }
        }
      }

    } else {
      for (var i = 0; i < Object.keys(fontNameData).length; i++) {
        cardHtml += '<div class="col-sm-3 p-1">';
        cardHtml += '<div class="card font' + (i+1) +'" id="' + (i+1) + '">';
        cardHtml += '<div class="card-body">';
        cardHtml += '<h5 class="text">' + cardText + '</h5>';
        cardHtml += '<p class="font_name">' + fontNameData[i+1] + '</p>';
        cardHtml += '</div>';
        cardHtml += '</div>';
        cardHtml += '</div>';
      }
    }
    $("#play_area").html(cardHtml);
    $(".font_name").hide();
    answer = rand(Object.keys(fontNameData).length);
    $("#answer_font").text(fontNameData[answer]);
    $("#opened_num").text("(" + openedFont.length + "/" + Object.keys(fontNameData).length + ")");
    $("#now_result").text("");
  }

  function open(targetObject) {
    $(targetObject).find(".font_name").show();
    openedFont.push(parseInt($(targetObject).attr("id")));
    console.log("openedFont");
    console.log(openedFont);
  }

  function next() {
    console.log('next() called');
    while (1) {
      // まだ使ってないお題になるまでループ
      answer = rand(Object.keys(fontNameData).length);
      if (openedFont.indexOf(answer) == -1){
        break;
      }
    }
    $("#answer_font").text(fontNameData[answer]);
    $("#opened_num").text("(" + openedFont.length + "/" + Object.keys(fontNameData).length + ")");
  }

  function complete() {
    console.log('complete() called');
    $("#opened_num").text("(" + openedFont.length + "/" + Object.keys(fontNameData).length + ")" + "終了");
    completeFlg = true;
  }

  function pass() {
    console.log('pass() called');
  }
});

              
            
!
999px

Console