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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Wordling</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto|Pacifico" rel="stylesheet">

</head>

<body>
  <div class="container text-center">

    <h1 class="logo">Wordling</h1>
    <p>a Simple word game that improves your spelling and builds your vocabulary.</p>

    <!-- Implement a start button! -->

    <p>Streak : <span id="distance">0</span> Time : <span id="time"></span> </p>

    <div class="game-boy text-center" id="game-area">
      <!-- container to contain the word and the correct or incorrect button -->
      <p>Is this word spelt correctly?</p>
      <h2 id="word">(start game)</h2>
      <p id="description" style="display:none;"></p>
      <div class="options">
        <button id="false-btn" class="red">No</button>
        <button id="true-btn" class="blue">Yes</button>
      </div>
    </div>

    <div class="game-boy" id="report" style="display: none;">
      <h3>It's a tricky one, let's check this word out!</h3>
      <div class="word-box text-left">
      <h3 id="gword"></h3>
      <p id="gdesc"></p>
      </div>
      <p id="ghelp" class="info"></p>
      <hr>
      <p id="totalstreak"></p>
      <p id="gtime"></p>
      <hr>
      <!-- badges -->
      <h3>New personal best!</h3>
      <!-- previous scores -->
      <p>Streak / Time</p>

      <button id="retry" class="btn-block blue">Let's beat these scores!</button>
    </div>

    <div class="text-center" id="victory" style="display: none;">
      <div class="game-boy ">
        <h1 class="logo" style="font-size: 35px; margin-top: 0px;">Congratulations!</h1>
        <p>You've beaten this round!</p>

        <button id="nextround" class="btn-block blue">Let's grow our streak!</button>
        <button class="btn-block blue">Challenge my friends!</button>

      </div>

      <!-- Share on social media to challenge friends. -->
    </div>

    <div class="game-boy text-left" id="overview" style="display:none;">
      <h3>Words Played</h3>
      <div id="words">


      </div>
      <hr>
      <h3>Correct</h3>
      <div id="correct">


      </div>
      <hr>
      <h3>Incorrect</h3>
      <div id="incorrect">


      </div>
    </div>

  </div>

</body>

</html>
              
            
!

CSS

              
                html {
  box-sizing: border-box;
  background-image: linear-gradient(to top, #37ecba 0%, #72afd3 100%);
  height: 100vh;
  background-attachment: fixed;
}

body {
  font-family: "Roboto", sans-serif;
  color: #fff;
}

.container {
  margin: 0 auto;
  width: 300px;
}

.game-boy {
  background-image: linear-gradient(120deg, #fdfbfb 0%, #ebedee 100%);
  color: #333;
  border: 1px solid #cecece;
  padding: 16px;
  border-radius: 10px;
  margin-bottom: 1em;
}

button {
  width: 49%;
  padding: 10px;
  border-radius: 5px;
  border: none;
  color: #333;
  cursor: pointer;
  font-weight: bolder;
  font-size: 14px;  
}

.btn-block {
  width: 100%;
  display: block;
  margin-bottom: 1em;
}

.red {
  background: #ff758c;
  color: #fff;
}

.blue {
  background: #00c9ff;
  color: #fff;
}

.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.logo {
  font-family: "Pacifico", cursive;
  font-size: 60px;
  font-weight: normal;
  margin-bottom: 0px;
}

#word{
  margin-top: 0px;
  font-size: 2em;
  text-align: center;
}

.info{
  border: 1px solid #a2f5ba;
  padding: 1em;
  background: #b1ffc8;
  border-radius: 5px;
}

.word-box{
  border: 1px solid #ddd;
  padding: 16px;
  #gword{
    font-size: 28px;
    margin: 0px; 
    color: #000;
  }
  #gdesc{
    font-size: 14px;
  }
}

hr{
  color: #ddd
}
              
            
!

JS

              
                //Functional prototype, will probably work on it some more in future.

// Set up variables
var score = 0;
var roundTime = 0; // time you took to get to the distance
var clock = document.querySelector("#time");
var streak = 0; // distance you travelled
var distance = document.querySelector("#distance");
var wordNumber = 0;
var gameOver = false;
var report = document.querySelector("#report");
var gameArea = document.querySelector("#game-area");
var victory = document.querySelector("#victory");
var overview = document.querySelector("#overview");
var incorrectWords = document.querySelector("#incorrect");
var correctWords = document.querySelector("#correct");

// Set up the data set

var json =
  '[{    "correct": "equipment", "wrong": ["equiptment", "equipament", "eqwipment"], "description": "an instrumentality needed for an undertaking or to perform a service.\'they made a check of their equipment\'", "help": "There is only one t in equipment, and it\'s at the end of the word."},{    "correct": "common", "wrong": ["comon", "commen", "comin"], "description": "occurring, found, or done often; prevalent.\'salt and pepper are the two most common seasonings\'", "help": "Remember that common has two o\'s and two m\'s"},{    "correct": "misspelt",    "wrong": ["mispelt", "mispellt", "misspellt"], "description": "spell (a word) wrongly.", "help": "Remember that miss has two s\'s and pelt only one l"},{    "correct": "whether",    "wrong": ["wherver", "whever", "wether"], "description": "expressing a doubt or choice between alternatives.\'he seemed undecided whether to go or stay\'", "help": "There is no V in whether and it has two h\'s"},{    "correct": "surprise",    "wrong": ["suprise", "supprise", "surpprize"], "description": "an unexpected or astonishing event, fact, etc. \'the announcement came as a complete surprise\'","help": "Remember the r before the only p and that only american english uses a z"}]';

var round = [];

var obj = JSON.parse(json);

var totalWords = obj.length;

var wordtext = document.querySelector("#word");
var wordDescription = document.querySelector("#description");

var displayedWord;
var correctWord;

/**
 * Next word
 */

function nextWord() {
  //randomize the spelling variation
  displayedWord = randomWord();
  correctWord = obj[wordNumber].correct;
  wordtext.innerHTML = displayedWord;
  wordDescription.innerHTML = obj[wordNumber].description;
}

/**
 *  Randomize which word to show
 */

function randomWord() {
  if (Math.random() * 10 > 5.1) {
    var x = Math.floor(Math.random() * obj[wordNumber].wrong.length);
    return obj[wordNumber].wrong[x];
  } else {
    return obj[wordNumber].correct;
  }
}

/**
 * Check if word was correct
 */
function checkWord(answer) {
  if (!gameOver) {
    isCorrect = false;

    if (correctWord === displayedWord) {
      if (answer === true) {
        isCorrect = true;
      }
    } else {
      if (answer === false) {
        isCorrect = true;
      }
    }

    var para = document.createElement("P"); // Create a <p> node

    // append to the correct or incorrect divs
    if (isCorrect) {
      var t = document.createTextNode(correctWord); // Create a text node
      para.appendChild(t);
      document.getElementById("correct").appendChild(para);
      streak++;
      distance.innerHTML = streak;

      // if all words reached then we should end game
      if (wordNumber < totalWords - 1) {
        wordNumber++;
        nextWord();
      } else {
        endGame("win");
      }
    } else {
      var t = document.createTextNode(
        correctWord.toUpperCase() +
          " was the correct word, you chose " +
          displayedWord +
          ". Tip : " +
          obj[wordNumber].help
      ); // Create a text node
      para.appendChild(t);
      document.getElementById("incorrect").appendChild(para);
      endGame("fail");
    }
  }
}

/**
 * End Game
 */

function endGame(result) {
  gameArea.style.display = "none";
  if (result == "win") {
    victory.style.display = "block";
  } else { 
    streak = 0;
    gameover= true;
    document.querySelector("#gword").innerHTML = obj[wordNumber].correct;
    document.querySelector("#gdesc").innerHTML = obj[wordNumber].description;
    document.querySelector("#ghelp").innerHTML = obj[wordNumber].help;
    document.querySelector("#totalstreak").innerHTML = "Streak : " + streak;
    document.querySelector("#gtime").innerHTML = "Time : " + clock.innerHTML;
    report.style.display = "block";
  }
  overview.style.display = "block";

  clearInterval(interval);
  (milliseconds = 0),
    (seconds = 0),
    (minutes = 0),
    (hours = 0),
    (millisecondstext = "");

  //@TODO
  // populate a results screen
  // Show word you lost on, show the correct spelling and description
  // show the distance you went and the time it took
  // show if you beat a previously failed word
  // Show if you did better this time than last time. (graph maybe)
}

/**
 * Generate the round from the data we received back from API
 */
function generateRound() {
  //randomize the words locally
  obj.sort(function(a, b){return 0.5 - Math.random()});
  
  // put the words in an array so we can push them to the front end.
  obj.forEach(function(element) {
    var node = document.createElement("P");
    var textnode = document.createTextNode(element.correct);
    node.appendChild(textnode);
    //document.getElementById("words").appendChild(node);
  });
  
  
  correctWords.innertHTML = "";
  incorrectWords.innerHTML = "";   
  
  interval = setInterval(updateTimer, 10);
  nextWord();
}

/**
 * Start the game, reset the scores and generate a new round.
 */

function startGame() {
  overview.style.display = "none";
  gameArea.style.display = "block";
  report.style.display = "none";
  victory.style.display = "none";
  correctWords.innertHTML = "";
  incorrectWords.innerHTML = "";
  gameOver = false;
  score = 0;
  wordNumber = 0;
  distance.innerHTML = streak;
  generateRound();
  //start round and timer
}

document.getElementById("true-btn").addEventListener("click", function() {
  checkWord(true);
});

document.getElementById("false-btn").addEventListener("click", function() {
  checkWord(false);
});

document.getElementById("nextround").addEventListener("click", function() {
  startGame();
});

document.getElementById("retry").addEventListener("click", function() {
  startGame();
});

/**
 * Stop watch timer.
 */
var milliseconds = 0,
  seconds = 0,
  minutes = 0,
  hours = 0,
  millisecondstext = "";
function updateTimer() {
  milliseconds += 10;
  millisecondstext = "";

  if (milliseconds == 1000) {
    seconds++;
    milliseconds = 0;
  }
  if (seconds == 60) {
    minutes++;
    seconds = 0;
  }
  if (minutes == 60) {
    hours++;
    minutes = 0;
  }
  if (milliseconds < 100) {
    millisecondstext += "0";
    if (milliseconds < 10) {
      millisecondstext += "0";
    }
  } else {
    millisecondstext = "";
  }

  clock.innerHTML =
    hours +
    " : " +
    minutes +
    " : " +
    seconds +
    " : " +
    millisecondstext +
    milliseconds;
}

startGame();

              
            
!
999px

Console