Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div id="outer-container">
  
  <div class="game-board">
  <div id="info-area" class="inner-wrap flexb25 ">
    
    <div id="title-box" class="box-wrap">
      <h1>ABC Sheep!</h1>
      <h2>ABC's on the Farm</h2>
    </div> <!-- END #title-box -->
    <div class="score-wrap">
      <div class="voiceinator flex-item-33" >

      <h1>Voice</h1>

      <select name="voice" id="voices">
        <option value="">Select A Voice</option>
      </select>

      <label for="rate">Rate:</label>
      <input name="rate" type="range" min="0" max="3" value="1" step="0.1">

      <label for="pitch">Pitch:</label>

      <input name="pitch" type="range" min="0" max="2" step="0.1">
      <button id="stop">Stop!</button>
    </div>  
      <h1 class="score flex-item-33" >0</h1></div>
      <div id="player-outer-wrap" class="flex-item-33" ></div>
   <div class="button-wrap">
    <button id="start-button" onClick="startGame()">Start!</button>
    <button id="stop-button"  onClick="stopGame()">Stop</button>
 </div>
    
    <div class="words" contenteditable>
      <p></p>
    </div>
    
  </div> <!-- END .inner-wrap -->
  <div class="inner-wrap flexb75 ">
  <div class="game-wrap persp-parent">
    <div class="game">
      <div class="hole hole1">
        <div class="mole">
          <div class="entry-holder"></div>
        </div>
      </div>
      <div class="hole hole2">
        <div class="mole">
          <div class="entry-holder"></div>
        </div>
      </div>
      <div class="hole hole3">
        <div class="mole">
          <div class="entry-holder"></div>
        </div>
      </div>
      <div class="hole hole4">
        <div class="mole">
          <div class="entry-holder"></div>
        </div>
      </div>
      <div class="hole hole5">
        <div class="mole">
          <div class="entry-holder"></div>
        </div>
      </div>
      <div class="hole hole6">
        <div class="mole">
          <div class="entry-holder"></div>
        </div>
      </div>
      

      
    </div> <!-- END .game -->
  </div> <!-- END .game-wrap -->  
    
  </div> <!-- END .inner-wrap 75percent--> 
  
</div> <!-- END .game-board -->

 <div id="instructions-wrap">
   <h3>NOTE:</h3> 
   <ul><li>This is made to work only in the Google Chrome laptop/desktop browser. Do not use other browsers as they are likely to have issues with parts of the voice recognition and comparison processes.</li>
  <li>This requires the child to speak the answer into a microphone. Permission must be given to Chrome to allow use of the microphone. It should ask you when you first load the game.</li>
  <li>A headset with a microphone is strongly recommended. This ensures the best pickup of the child's voice and avoids cross talk.</li>
     </ul>
   
   <h3> Fun and Practice</h3>
  <p>I built this for my kids for a fun and interactive way to practice their ABC's. They were too small to use a keyboard, so the game play is all voice driven. To play, you'll need a microphone and speakers. Additionally, you may need to grant the browser permission to access your microphone. A gaming headset with a microphone and a quiet room are recommended.</p>

 <h3>How to Play</h3>   
<ul>
  <li>Click the "Start" button.
  A sheep will appear from behind a bush, displaying a letter on its body.</li>
  <li>Speak the letter aloud into the microphone.
  The game will respond with a voice confirmation, letting you know if your answer is correct.</li>
  <li>The score will be updated, and another sheep will appear with a new letter.</li>
 <li>Adjusting the Game Pace</li>
  <li>Want to make the game more challenging? You can modify the delay time in the JavaScript code to adjust the pace of the game.</li>
   </ul>
   <p>
  <h3>Additional Note:</h3>
  <p>This game is not fully bug-tested, but it has been successfully played by my kids many times. If you have any questions or issues, please email <a src="mailto:general@glassinteractive.com">general@glassinteractive.com</a></p>
  </div><!-- END .instructions-wrap -->
  
</div><!-- END #outer-container -->
              
            
!

CSS

              
                
*, *:before, *:after {
  box-sizing: inherit;
}

html {
  box-sizing: border-box;
  font-size: 10px;
  background: hsla(91, 54%, 9%, 1);
    background: linear-gradient(0deg, #43691f, #dbe4ed);
}

body {
  display: flex;
  min-height: 100vh;
  font-family: 'Roboto', Arial, sans-serif;
  margin: 0;
}

#outer-container {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: auto;
  border-radius: 50px;
  padding: 2em;

}

h1 {
    text-align: center;
    font-size: 10rem;
    line-height: 1;
    letter-spacing: 0.2em;
    margin-bottom: 0.5em;
    padding-top: 0.5em;
    margin-top: auto;
}
h2 {
    text-align: center;
    font-size: 5rem;
    letter-spacing: 0.3em;
    line-height: 1;
    margin-bottom: 0.5em;
    margin-top: 0.5em;
}

#title-box h1 {
    font-size: 4rem;
}

#title-box h2 {
    font-size: 2rem;
}

#title-box {
  padding: 0 3em
}

#info-area {
    max-width: 1000px;
    margin: auto;
    width: 100%;
    padding: 0;
    background: rgba(255, 255, 255, 0.48);
    color: #0a0a0ae0;
    z-index: 1;
    border-radius: 35px;
}

.game-board {
  position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: auto;
    justify-content: start;
    max-height: 768px;
    max-width: 1120px;
    overflow: hidden;
    background-image: url(http://www.glassinteractive.com/wp-content/uploads/2019/02/background-grass.jpeg);

    background-image: url('https://cdn.clipart.email/555432c1c055c53a8cf5784358330f2a_barnyard-backgrounds-clipart_1024-768.jpeg');

    background-image: url('http://www.glassinteractive.com/wp-content/uploads/2019/02/barn-n-clouds-EDITED.jpg');

    background-position: bottom;
    background-repeat: no-repeat;
    background-size: cover;
   box-shadow: 1px 1px 10px 0 black, 3px 3px 20px -3px black;
   border-radius: 50px;
   border: 1px outset white;
   border-right: none;
   border-bottom: none;
}

.score-wrap {
    display: flex;
    justify-content: center;
    align-items: top;
    flex-wrap: wrap;
    background: #ffffffd9;
    color: #43691f;
  border-radius: 50px;
}

.score {
  display: flex;
  align-items: center;
  justify-content: center;
  align-items: center;
  margin: 0;
  line-height: 1;
   font-weight: 700;
  max-width:min-content;

}

.flex-item-33 {
    flex-basis: 33%;
    min-width: 200px;
    flex-grow: 1;
}

.game-board.hide .flexb25 {
  transform: scale(0);
}


.button-wrap {
    display: flex;
    width: 98%;
    margin: auto;
    position: relative;
    min-height: 5em;
    justify-content: center;
    border-radius: 50px;
  overflow: hidden;
  box-shadow: inset -5px -5px 10px -7px black, inset 5px 5px 10px -7px white;
}

.game-board button {
    min-height: 2em;
    width: 100%;
    background: #43691f;
    border: none;
}

#start-button, #stop-button {
    color: rgba(255, 255, 255, 0.7);
    font-variant: all-small-caps;
    font-size: 2em;
    font-weight: 700;
    letter-spacing: 0.1em;
    font-family: inherit;
    box-shadow: inherit;
}

#stop-button {
    background: hsl(0deg 54% 27%);
    width: 39rem;
}
.inner-wrap {
    display: flex;
    flex-direction: column;
    padding: 2rem
}

.flexb25 {
 flex-basis: 25%;
}

.flexb75 {
 flex-basis: 25%;
}

.game:before {
    content: ' ';
    position: absolute;
    display: block;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.persp-parent {

    perspective: 600px;
    perspective: 300px;
    perspective: 1200px;
    transform-style: preserve-3d;
    transform: translatey(200px) scale(0.7) translateY(-14%);
    transform: translatey(200px) scale(1.2) translateY(-20%);
}


.game {
    position: relative;
    width: 100%;
    min-height: 800px;
    display: flex;
    padding: 0 4rem 4rem;
    flex-wrap: wrap;
    margin: 0 auto;
    transform: rotateX(70deg) translateZ(0) translateY(23%);
  rotateX(59deg) translateZ(0) translateY(-20%);
    transform: rotateX(60deg) translateZ(-185px) translateY(-74%);
    transform: rotateX(60deg) translateZ(-304px) translateY(-117%);
    transform: rotateX(70deg) translateZ(0) translateY(-50%);
    perspective: inherit;
    transform-style: preserve-3d;
}

.game {
   max-width: 1200px;
   min-width: 580px;
}

.hole {
    flex: 1 0 33.33%;
    position: relative;
    height: 280px;
    min-width: 250px;
    max-width: 250px;
    transform: rotatex(-45deg);
  transform: rotatex(-35deg);
  margin: 50px auto;
  transform-origin: bottom;
}

.hole:after {
    display: flex;
    background: url(https://res.cloudinary.com/do0dxcsdm/image/upload/v1728511986/1970984_u5mpnh.png);
/*       background: url('  http://www.inline.ie/images/bale2.png'); */
    background-size: contain;
    content: '';
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 2;
    bottom: 0;
    background-position: bottom;
    background-repeat: no-repeat;
}

.mole {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  background: URL("https://res.cloudinary.com/do0dxcsdm/image/upload/v1728513411/Sheep_cl1onk.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  top: 100%;
  width: 100%;
  transform: translateY(-50%) scale(1);
  height: 0;
  transition: all 0.4s;
  overflow: hidden;
}

.entry-holder {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 2em;
    transform: translate(70%, 12%);
    height: 2em;
    /* background: black; */
    /* background-image: url(http://www.glassinteractive.com/wp-content/uploads/2019/02/Blackboard-72dpi.png); */
    /* color: #ffffffc9; */
    font-size: 5rem;
    /* border: 2px outset #464646; */
    /* text-shadow: -12px -5px 30px #ffffff59, 5px 7px 30px #ffffff2b, 11px 16px 50px #ffffffb5, -20px 17px 70px #ffffff2b; */
    text-shadow: 0 1px 1px white;
    color: #000000cc;
}

.hole.up .mole {
  top: 0;
  height: 100%;
  transform: translateY(-55%) scale(1);
}

.words {
    width: 98%;
    display: flex;
    margin: auto;
    text-align: center;
    font-size: calc(1rem + 0.5vw);
    height: auto;
    font-weight: 700;
    padding: 0.25em 1em;
    max-height: 5em;
    min-height: 3em;
    flex-grow: 1;
    border-radius: 50px;
    position: relative;
      text-shadow: none;
    box-shadow: 0 0 200px 0 inset white;
}
    
    .words:before {
      content: '';
      position: absolute;
      width: 4px;
      top: 0;
      left: 30px;
      bottom: 0;
    }

.words p {
    margin: auto;
}

.player-setup-outer-wrap {
    position: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    top: 0;
    Left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.75);
    box-shadow: 0 0 80px 0 white;
    transform: scale(0);
    transition; 1s all ease;
    z-index:1000;
    
}

.player-setup-outer-wrap.open {
    transform: scale(1);
    transition; 1s all ease;
}

input#player-quantity {
    min-width: 100px;
    min-height: 100px;
    margin: 50px;
    font-size: 45px;
    font-weight: 700;
    text-align: center;
    text-indent: 0.25em;
    background: rgba(255,255,255, 0.5);
}

#player-setup-form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
      max-width: 800px;
}

#player-setup-form h2 {
    letter-spacing: 0;
    margin: 1em auto 0;
}

#player-boxes {
    justify-content: space-evenly;
    font-size: 1.5em;
    text-align: center;
    letter-spacing: 0.2em;
}

#player-boxes h3 {
    flex-basis: 100%;
    flex-grow: 1;
    text-align: center;
}

#player-boxes h4 {
    margin: 0;
}

.player-score {
    font-size: 4em;
}

/*****************************
      Voice Controls
*****************************/

.voiceinator,#player-boxes {
    display: flex;
    flex-wrap: wrap;
    padding: 0 4% 0.5em;
    width: 100%;
    margin: 0 auto;
    border-radius: 0 0 1rem 1rem;
    position: relative;
    overflow: hidden;
    color: white;
    z-index: 1;
    background: transparent;
    color: inherit;
    font-weight: 700;
    border-radius: 50px;
}

.voiceinator h1, #player-boxes h3 {
     width: 100%;
    margin: 0 auto 0.25em;
    padding: 0.25em;
    background: #43691fb8;
    text-align: center;
    box-shadow: 0 0 15px -3px #ffffff61, inset -1px 5px 15px -5px hsla(0, 0%, 0%, 0.38);
    font-size: 2rem;
    font-weight: 100;
    text-shadow: 0px -1px 0 #000000;
    color: hsla(0, 0%, 100%, 0.9);
    border-radius: 50px;
}

.voiceinator input,
.voiceinator button,
.voiceinator select,
.voiceinator textarea {
    width: 100%;
    display: block;
    margin: 0.2em;
    padding: 5px;
    border: 0;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.75);
    outline: 0;
    border-radius: 10px;
}

.voiceinator input {
    width: calc(100% - 4em);
}

textarea {
  height: 20rem;
}

.voiceinator button {
    background: rgba(255, 255, 255, 0.75);
    border: 0;
    border-radius: 10px;
    width: 100%;
    margin-bottom: 0;
    font-size: 1rem;
    padding: 0.3em;
    cursor: pointer;
    position: relative;
}

.voiceinator button:active {
  top: 2px;
}

div#instructions-wrap {
position: absolute;
    display: block;
    background: white;
    padding: 1em 2em 1em;
    max-width: 80%;
    height: 1000px; 
    width: 100%;
    max-height:2em;
    margin: auto;
    border-radius: 50px;
    top: 0;
    left: 50%;
    z-index: 10;
    transform: translate(-50%, 0%);
    font-size: 16px;
    max-height: 1em;
    overflow: hidden;
    transition: 0.3s all ease;
    transform-origin: top;
}

div#intro-instructions-wrap {
    max-width: 800px;
    margin: auto;
    font-size: 14px;
    background: white;
    padding: 1em 2em;
    border-radius: 50px;
}

div#instructions-wrap ul {
  margin-top: 0;
  padding-top:0;
  margin-bottom:0;
    padding-bottom;
}

div#instructions-wrap:after {
    content: "Hover Here for Instructions";
    position: absolute;
    display: flex;
    top: 0;
    left: 0;
    width: 100%;
    height: 2em;
    text-align: center;
    background: #43691f;
    color: white;
    align-items: center;
    justify-content: center;
}

div#instructions-wrap:hover {
    max-height: 90%;
}

div#instructions-wrap :first-child {
    margin-top: 2em;
}
              
            
!

JS

              
                //--------------------------------
//  Game Settings
//--------------------------------
const gameLength = 80000;
const upTime = 4000


//--------------------------------
//  Variables
//--------------------------------
const holes = document.querySelectorAll('.hole');
const scoreBoard = document.querySelector('.score');
const moles = document.querySelectorAll('.mole');
const words = document.querySelector('.words');
const p = document.querySelector('.words p')
let lastHole; 
let timeUp = false;
let score = 0;
let entry;
let time;
let hole;
let popUp;
let speakingCheck;
let gramagramResult = false;
let playerData = {};
let currentPlayer;
let currentPlayerNumber = 0;
let playerQuantity = 0;
let resetScoreBoxes = false;
let voiceListenOn = false;


function registerPlayers() {

	// Create overlay
	let overlayHTML = document.createElement('div');
  
  overlayHTML.className = 'player-setup-outer-wrap';
  
  overlayHTML.innerHTML = '<div id="player-setup-overlay" class="overlay" bacground="green" ></div>';
  
	document.body.appendChild(overlayHTML);
  
	const playerSetupOverlay = document.getElementById('player-setup-overlay');
  const scoreboardArea = document.querySelector('.game-board' );
	playerSetupOverlay.parentElement.className += ' open';
  scoreboardArea.className += ' hide';
  
    //Find out how many players
		playerSetupOverlay.innerHTML = `<form id="player-setup-form" 	class="setup-form" ><h2>How many people are playing?</h2><input type="number" id="player-quantity" name="player-quantity" min="1" max="2"></form>
    <div id="intro-instructions-wrap">
   <h3>NOTE:</h3> 
   <ul><li>This is made to work only in the Google Chrome laptop/desktop browser. Do not use other browsers as they are likely to have issues with parts of the voice recognition and comparison processes.</li>
  <li>This requires the child to speak the answer into a microphone. Permission must be given to Chrome to allow use of the microphone. It should ask you when you first load the game.</li>
  <li>A headset with a microphone is strongly recommended. This ensures the best pickup of the child's voice and avoids cross talk.</li>
     </ul>
  </div>`
   
 let playersSetupForm =  document.getElementById('player-setup-form');
 
  playersSetupForm.addEventListener('submit', playerNumberHandler);
  
  
  
  function playerNumberHandler(e) {
    
    e.preventDefault();
    
    playerQuantity = document.getElementById("player-quantity").value;
    
    setupPlayerBoxes(playerQuantity);
  }
  
  
  function setupPlayerBoxes(amount) {
    
       // Setup gameboard
   scoreboardArea.classList.remove('hide');
  playerSetupOverlay.parentElement.classList.remove('open');
   
   let playerBoxes = document.getElementById('player-outer-wrap');
   
   playerBoxes.innerHTML = '<div id="player-boxes"  class="player-boxes-wrap" ><h3>Players</h3></div>';
   
   let scoreBoardArea = document.querySelector('.score-wrap');
   
   scoreBoardArea.appendChild(playerBoxes);
   
   let playerBoxWrap = document.getElementById('player-boxes');
   
   for(i = 1; i <= amount; i++) {
     
      // Player data
      let newPlayerData = {number: i, id: 'player-' + i, name: 'Player ' + i, score: 0, totalscore: 0}
     
      playerData[i] = newPlayerData;

     
     // Player box setup
      let playerBoxContent = playerBoxWrap.innerHTML;
     
    playerBoxWrap.innerHTML = playerBoxContent + '<div id="' + playerData[i]['id'] + '"><h4>' + playerData[i]['name'] + '</h4><div class="player-score" >' + playerData[i]['score'] + '</div> </div>';
   }
 }
}
registerPlayers()



function resetPlayerBoxes(amount) {
  
  let existingPlayerBoxes = document.querySelectorAll('.player-score');

  existingPlayerBoxes.forEach(box => {
  
         box.innerText = 0;
                              })
}



function startGame() {
  console.log('Started...');

  voiceListenOn = true;
  time = 0;
  
  if(resetScoreBoxes) {
    
  let playerBox = document.getElementById(currentPlayer.id);
  
  let scoreHolder = playerBox.querySelector('.player-score');
  
  
    Object.keys(playerData).forEach(key => {

    playerData[key]['score'] = 0;
  })
   
   
    resetPlayerBoxes(playerQuantity);
    resetScoreBoxes = false;
  }
  
  scoreBoard.textContent = 0;
  
  p.textContent = '';
  
  score = 0;
  currentPlayerNumber++;
  currentPlayer = playerData[currentPlayerNumber]
  timeUp = false;
  
  clearTimeout;
  setTimeout(updatePlayerScore, gameLength);
  
    //  Start the game
    dropMole();
  
}



function randomHole(holes) {
  
  const idx = Math.floor(Math.random() * holes.length);
  
  const hole = holes[idx];
  
  if(hole === lastHole) {
    
    return randomHole(holes)
  }

  lastHole =hole;
  return hole;
}



function randomTime(min, max) {
  return Math.round(Math.random() * (max - min) + min);
} 



function randomEntry(min, max) {
  
    return Math.random().toString(36).substr(2, 1);
}



function peep() {
  clearTimeout(popUp);
  
  time = randomTime(2000, 3000);
  hole = randomHole(holes);
  entry = randomEntry(0, 20);
  entry = entry.toUpperCase();
  const mole = hole.querySelector('.entry-holder');
  mole.textContent = entry;


  var synth = window.speechSynthesis;
  
  if (!synth.speaking) {
    hole.classList.add('up');
    popUp = setTimeout (() => {
      dropMole();
    }, upTime);
    
  } else {
    

    speakingCheck = setInterval(function(){
        if (!synth.speaking) {

          clearInterval(speakingCheck);
            hole.classList.add('up');
    popUp = setTimeout (() => {
      dropMole();
    }, upTime);
    
  }
    }, 500);
    }; 
}



function dropMole() {
  clearTimeout(popUp);
  holes.forEach(hole => hole.classList.remove('up'))
  
  if(!timeUp) {
    
        popUp = setTimeout(peep, time);
  };
}



//  Speech recognition
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.interimResults = true;
recognition.lang = 'en-US';
recognition.start();
recognition.addEventListener('result', processHumanResponse);
recognition.addEventListener('end', function() {

  var synth = window.speechSynthesis;

  testSpeaking = setInterval(function(){
console.log('synth.speaking',synth.speaking)
    if (!synth.speaking) {

      clearInterval(testSpeaking);

      recognition.start();
    }
  }, 500);
});



//********************************
//  Answer Detection and Testing
//********************************
function processHumanResponse(e) {
 
  if(voiceListenOn) {
  

  const transcript = Array.from(e.results)
                            .map(result => result[0])
                            .map(result => result.transcript)
                            .join('');
  

  const poopScript = transcript.replace(/poop|poo|shit|dump/gi, '💩');
   
  p.textContent = poopScript;

  if (e.results[0].isFinal) {

    var answer = event.results[0][0].transcript;
    
    entry = String(entry);
    
    answer = String(answer).toUpperCase();
    
    gramagramCheck(entry, answer);

    if(answer.includes(entry) || gramagramResult === true) {

      p.textContent = String(entry) + ' is Correct!';

      msg.text = document.querySelector('.words p').textContent;
     
      bonk(e);
      
      toggle();
      
    } else {

      p.textContent = answer + ' is wrong. Try Again!';
       msg.text = document.querySelector('.words p').textContent;
      toggle();
    }
  }
}
}


function bonk(e) {
  if(!e.isTrusted) return; // Checks for faking a click
  score++;
  //this.classList.remove('up');
  scoreBoard.textContent = score;
  clearTimeout(popUp);
  dropMole();
}



function stopGame() {
  
  voiceListenOn = false;
  timeUp = true;
  
  dropMole();
}



function updatePlayerScore() {
  
  let playerBox = document.getElementById(currentPlayer.id);
  
  let scoreHolder = playerBox.querySelector('.player-score');
  
 
    playerData[currentPlayer.number]['score'] = score;

  scoreHolder.innerText = score;
  
  nextPlayer();
  
}


function encouragementLogic() {
    
  endScore = Number(scoreBoard.textContent);
    
  if( endScore <= 3 ) {
    
    p.textContent = 'Your score is ' + score + '. Keep practicing and you will be great! ';
    
      msg.text = document.querySelector('.words p:first-child').textContent;

  } else {
    
      if( endScore > 3 && endScore <= 7) {
        
              p.textContent = 'Your score is ' + score + '. That is really good! Keep practicing and you will be great! ';
            
              msg.text = document.querySelector('.words p:first-child').textContent;
        
          } else {
            
                  if( endScore > 7 && endScore < 10) {
 
                       p.textContent = 'Your score is ' + score + '. You are doing GREAT! ';
                       msg.text = document.querySelector('.words p:first-child').textContent;
     
                  } else {
                    
                    if( endScore == 10) {
                      
                      p.textContent = 'Your score is ' + score + '. You are PERFECT! That is OUTSTANDING! ';
                      msg.text = document.querySelector('.words p:first-child').textContent;
                    } 
                }
          }
    }

  toggle();
}


function nextPlayer() {
  
  if(currentPlayer.number < playerQuantity) {
    
    stopGame();
     
    encouragementLogic();
    
    let nextPlayerStartMsg = function() {
      
      p.textContent = 'Player 2, click the START button!';
    
      msg.text = document.querySelector('.words p:first-child').textContent;
    
      toggle();
    }
    
    setTimeout(nextPlayerStartMsg, 5000);
    
    // let playerText = document.getElementById('player-boxes');
    //  playerText.querySelector('h3').innerText = 'Player 2, click the START button!';
   
  } else {
    
    endGame();
    
    encouragementLogic();
    
 
    let topScore = 0;
    let gameWinnner = '';
    Object.keys(playerData).forEach(key => {
    
      let thisScore = playerData[key]['score'];
      let thisplayer= playerData[key]['name'];
     
      if(thisScore > topScore) {
      topScore = thisScore;
      gameWinnner = thisplayer;
      } else if (thisScore == topScore) {
        
        if(topScore > 0) {
           gameWinnner = ' a tie between ' + gameWinnner + ' and ' + thisplayer;
        } else {
          gameWinnner = ' a tie because there no points scored'
        }
       
      }
    });
    
    let nextPlayerStartMsg = function() {
      
      p.textContent = 'The winner is ' + gameWinnner + '!!!   Click the START button to play again!';

      msg.text = document.querySelector('.words p:first-child').textContent;
    
      toggle();
    }
    
   
    setTimeout(nextPlayerStartMsg, 5000);
    
  }
}



function endGame() {
  
  voiceListenOn = false;
  timeUp = true;
  currentPlayerNumber = 0;
  resetScoreBoxes = true;
  
}



//*******************
//    Voicing
//*******************
const msg = new SpeechSynthesisUtterance();
  let voices = [];
  const voicesDropdown = document.querySelector('[name="voice"]');
  const options = document.querySelectorAll('[type="range"], [name="text"]');
  // const speakButton = document.querySelector('#speak');
  const stopButton = document.querySelector('#stop');
  msg.text = document.querySelector('.words').textContent;



  function populateVoices() {
    voices = this.getVoices();
    voicesDropdown.innerHTML = voices
      .filter(voice => voice.lang.includes('en'))
      .map(voice => `<option value="${voice.name}">${voice.name} (${voice.lang})</option>`)
      .join('');
  }



  function setVoice() {
    
    msg.voice = voices.find(voice => voice.name === this.value);
    toggle();
  }



  function toggle(startOver = true) {
    recognition.stop();
    speechSynthesis.cancel();
    if (startOver) {
      speechSynthesis.speak(msg);
    }

  }



  function setOption() {
    msg[this.name] = this.value;
    toggle();
  }



  speechSynthesis.addEventListener('voiceschanged', populateVoices);
  voicesDropdown.addEventListener('change', setVoice);
  options.forEach(option => option.addEventListener('change', setOption));
  // speakButton.addEventListener('click', toggle);
  stopButton.addEventListener('click', () => toggle(false));

function arrayContains(needle, arrhaystack) {
    return (arrhaystack.indexOf(needle) > -1);
}



function gramagramCheck(thisentry, thisanswer) {
  
      const gramagrams = {
      0:  ['OH', 'ZERO', 'O'],
      1:  ['ONE', 'WON', 'JUAN'],
      2:  ['TWO', 'TO', 'TOO'],
      3:  ['THREE', 'TREE', 'TREES', 'ME', 'BE', 'BEE', 'SEE','SEA','C', 'D', 'V', 'KNEE'],
      4:  ['FOUR', 'FOR', , 'POOR', 'MORE', 'STORE', 'LORE', 'OR', 'BORE', 'SNORE', 'CORE', 'DOOR', 'YORE'],
      5:  ['FIVE','HIVE','LIVE','KNIFE', 'THRIVE'],
      6:  ['SIX','STICK', 'STICKS','PIC', 'PICS', 'PICK', 'PICKS', 'LICK', 'LICKS', 'RICK', 'RICKS', 'KICK', 'KICKS', 'KIX', 'MIX', 'FIX', 'WICKS', 'WIX', 'TICK', 'TICKS', 'BLITZ'],
      7:  ['SEVEN', 'HEAVEN'],
      8:  ['EIGHT', 'EIGHTY', 'ATE', 'WAIT', 'LATE', 'MATE'],
      9:  ['NINE', 'LINE', 'FINE', 'TIME', 'TWINE', 'SINE'],
      10: ['TEN', 'LEN', 'LEND', 'SPEND', 'HEN', 'MEN', 'BEN', 'WHEN'],
      11: ['ELEVEN', 'HEAVEN', 'IN HEAVEN', 'E 11'],
      12: ['TWELVE'],
      13: ['THIRTEEN'],
      14: ['FOURTEEN', 'FOUR TEEN'],
      15: ['FIFTEEN', 'FITH TEEN'],
      A: ['THEY', 'HAY', 'HEY'],
      B:  ['SEA', 'SEAS','SEE', 'SEEDY', 'SEES', 'C', 'D', 'V', 'P', 'WE', 'ELSIE', 'KNEE', 'THREE', 'TREE', 'ME', 'PEACE', 'THE', 'THESE'],
      C:  ['SEA', 'SEAS','SEE', 'SEEDY', 'SEES', 'G', 'V', 'P', 'WE', 'ELSIE', 'KNEE', 'THREE', 'TREE', 'THE', 'THESE',  'ME', 'BE', 'BEE'],
      D:  ['THREE', 'TREE', 'THE', 'THESE', 'ME', 'BE', 'BEE', 'SEE', 'SEA', 'B', 'V', 'P', 'WE', 'KNEE'],
      H:  ['EIGHT','8','HATE', 'ATE', 'WAIT', 'LATE', 'MATE'],
      I:  ['AYE','EYE','EYES'],
      K:  ['DECAY'],
      L:  ['ELSIE', 'EL'],
      O:  ['OH', 'ZERO', '0'],
      P:  ['KEWPIE', 'B', 'C', 'D', 'V'], 
      Q:  ['CUE', 'CUES', 'CUTIE', 'KEWPIE'],
      R:  ['ARE', 'BAR', 'PAR'],
      T:  ['CUTIE', 'EIGHTY'],
      U:  ['EWES', 'EWE', 'YEW', 'YEWS'],
      V:  ['SEA', 'SEAS','SEE', 'SEEDY', 'SEES', 'C',  'ELSIE', 'KNEE', 'THREE', 'TREE', 'THE', 'THESE', 'ME', 'BE', 'BEE'],
      X:  ['HEX'],
      Y:  ['WISE'],
      Z:  ['SEA', 'SEAS','SEE', 'SEEDY', 'SEES', 'G', 'V', 'C', 'ELSIE', 'KNEE', 'THREE', 'TREE', 'THE', 'THESE', 'ME', 'BE', 'BEE']
  } 
  
      let entryUpper = thisentry;
  
      let answerUpper =thisanswer;
  
      keys = Object.keys(gramagrams);
  
      gramagramResult = false;
  
      if(gramagrams[thisentry]) {

            gramagrams[thisentry].forEach(item => { 

              if(item === thisanswer) {

                    gramagramResult = true;
                 } 
            })
       } 
}
              
            
!
999px

Console