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 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-buton" onClick="startGame()">Start!</button>
    <button id="stop-buton"  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 -->

              
            
!

CSS

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

html {
  box-sizing: border-box;
  font-size: 10px;
  background: hsla(91, 54%, 9%, 1);
    background-image: url(https://www.transparenttextures.com/patterns/pool-table.png);
}

body {
  display: flex;
  min-height: 100vh;
  font-family: 'Amatic SC', cursive;
  margin: 0;
}

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;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.75), 0 -1px 3px rgba(0, 0, 0, 0.75);
    z-index: 1;
    border-radius: 35px;
}

.game-board {
    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;
}

.score {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3rem;
  margin: 0;
  line-height: 1;
}

.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: #43691fc9;
    border: none;
}

#start-buton, #stop-buton {
    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-buton {
    background: hsla(0, 54%, 27%, 0.8);
    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(http://www.pngonly.com/wp-content/uploads/2017/05/Bush-Dark-Green-PNG.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://upload.wikimedia.org/wikipedia/commons/e/e3/Sheep.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(-34%) 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;
}

#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;
}

.voiceinator h1, #player-boxes h3 {
    width: 100%;
    margin: 0 auto 0.25em;
    padding: 0.25em;
    background: #0119014d;
    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;
    font-family: 'Pacifico', cursive;
    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%;
    font-family: 'Pacifico', cursive;
    margin-bottom: 0;
    font-size: 1rem;
    padding: 0.3em;
    cursor: pointer;
    position: relative;
}

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

JS

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


//--------------------------------
//  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';
  
    //Findout 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>'
   
 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}
     console.log('newPlayerData',newPlayerData);
      playerData[i] = newPlayerData;
     console.log('playerData ',playerData );
     
     // 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');
   console.log('existingPlayerBoxes', existingPlayerBoxes);
  existingPlayerBoxes.forEach(box => {
    console.log('box', 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');
  
    console.log('playerData',playerData);
    Object.keys(playerData).forEach(key => {
    console.log('key', key);
    console.log('playerData[key]',playerData[key]);
    playerData[key]['score'] = 0;
  })
    console.log('playerData',playerData);
   
    resetPlayerBoxes(playerQuantity);
    resetScoreBoxes = false;
  }
  
  scoreBoard.textContent = 0;
  
  p.textContent = '';
  
  score = 0;
  currentPlayerNumber++;
  currentPlayer = playerData[currentPlayerNumber]
  console.log('*currentPlayer*', currentPlayer)
  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() {
    console.log('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() {
    console.log('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(){

    if (!synth.speaking) {

      clearInterval(testSpeaking);

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



//********************************
//  Answer Detection and Testing
//********************************
function processHumanResponse(e) {
  if(voiceListenOn) {
  
 console.log('e',e);
  const transcript = Array.from(e.results)
                            .map(result => result[0])
                            .map(result => result.transcript)
                            .join('');
  
  console.log('transcript', transcript);
  const poopScript = transcript.replace(/poop|poo|shit|dump/gi, '💩');
    console.log('transcript',transcript);
  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);
console.log('p1',p)
    if(answer.includes(entry) || gramagramResult === true) {
console.log('p2',p)
      p.textContent = String(entry) + ' is Correct!';
console.log('p3',p)
      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;
  console.log('playerData',playerData);
  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 => {
      console.log('key',key)
      let thisScore = playerData[key]['score'];
      let thisplayer= playerData[key]['name'];
      console.log('thisplayer',thisplayer)
      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);
    console.log(msg.voice);
    toggle();
  }



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

  }



  function setOption() {
    console.log(this.name, this.value);
    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:  ['HIVE','LIVE','KNIFE', 'THRIVE'],
      6:  ['STICK', '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'],
      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