Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <div class="container" id="target">
		<div class="row col-md-12" id="prompt-container">
			<div class="row col-xs-12" id="yellow-block"></div>
			<div class="row col-lg-12" id="sentence"></div>
			<div class="row col-lg-12 text-center" id="feedback"></div>
			<div class="row col-lg-12 text-center" id="target-letter"></div>
		</div>
		<div class="text-center keyboard-container" id="keyboard-upper-container">
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="126">~</span>
				<span class="well well-lg key" id="33">!</span>
				<span class="well well-lg key" id="64">@</span>
				<span class="well well-lg key" id="35">#</span>
				<span class="well well-lg key" id="36">$</span>
				<span class="well well-lg key" id="37">%</span>
				<span class="well well-lg key" id="94">^</span>
				<span class="well well-lg key" id="38">&</span>
				<span class="well well-lg key" id="42">*</span>
				<span class="well well-lg key" id="40">(</span>
				<span class="well well-lg key" id="41">)</span>
				<span class="well well-lg key" id="95">_</span>
				<span class="well well-lg key" id="43">+</span>
			</div>
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="81">Q</span>
				<span class="well well-lg key" id="87">W</span>
				<span class="well well-lg key" id="69">E</span>
				<span class="well well-lg key" id="82">R</span>
				<span class="well well-lg key" id="84">T</span>
				<span class="well well-lg key" id="89">Y</span>
				<span class="well well-lg key" id="85">U</span>
				<span class="well well-lg key" id="73">I</span>
				<span class="well well-lg key" id="79">O</span>
				<span class="well well-lg key" id="80">P</span>
				<span class="well well-lg key" id="123">{</span>
				<span class="well well-lg key" id="125">}</span>
				<span class="well well-lg key" id="124">|</span>
			</div>
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="65">A</span>
				<span class="well well-lg key" id="83">S</span>
				<span class="well well-lg key" id="68">D</span>
				<span class="well well-lg key" id="70">F</span>
				<span class="well well-lg key" id="71">G</span>
				<span class="well well-lg key" id="72">H</span>
				<span class="well well-lg key" id="74">J</span>
				<span class="well well-lg key" id="75">K</span>
				<span class="well well-lg key" id="76">L</span>
				<span class="well well-lg key" id="58">:</span>
				<span class="well well-lg key" id="34">"</span>
			</div>
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="90">Z</span>
				<span class="well well-lg key" id="88">X</span>
				<span class="well well-lg key" id="67">C</span>
				<span class="well well-lg key" id="86">V</span>
				<span class="well well-lg key" id="66">B</span>
				<span class="well well-lg key" id="78">N</span>
				<span class="well well-lg key" id="77">M</span>
				<span class="well well-lg key" id="60">&#60</span>
				<span class="well well-lg key" id="62">&#62</span>
				<span class="well well-lg key" id="63">?</span>
			</div>
		</div>
		<div class="text-center keyboard-container" id="keyboard-lower-container">
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="96">`</span>
				<span class="well well-lg key" id="49">1</span>
				<span class="well well-lg key" id="50">2</span>
				<span class="well well-lg key" id="51">3</span>
				<span class="well well-lg key" id="52">4</span>
				<span class="well well-lg key" id="53">5</span>
				<span class="well well-lg key" id="54">6</span>
				<span class="well well-lg key" id="55">7</span>
				<span class="well well-lg key" id="56">8</span>
				<span class="well well-lg key" id="57">9</span>
				<span class="well well-lg key" id="48">0</span>
				<span class="well well-lg key" id="45">-</span>
				<span class="well well-lg key" id="61">=</span>
			</div>
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="113">q</span>
				<span class="well well-lg key" id="119">w</span>
				<span class="well well-lg key" id="101">e</span>
				<span class="well well-lg key" id="114">r</span>
				<span class="well well-lg key" id="116">t</span>
				<span class="well well-lg key" id="121">y</span>
				<span class="well well-lg key" id="117">u</span>
				<span class="well well-lg key" id="105">i</span>
				<span class="well well-lg key" id="111">o</span>
				<span class="well well-lg key" id="112">p</span>
				<span class="well well-lg key" id="91">[</span>
				<span class="well well-lg key" id="93">]</span>
				<span class="well well-lg key" id="92">\</span>
			</div>
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="97">a</span>
				<span class="well well-lg key" id="115">s</span>
				<span class="well well-lg key" id="100">d</span>
				<span class="well well-lg key" id="102">f</span>
				<span class="well well-lg key" id="103">g</span>
				<span class="well well-lg key" id="104">h</span>
				<span class="well well-lg key" id="106">j</span>
				<span class="well well-lg key" id="107">k</span>
				<span class="well well-lg key" id="108">l</span>
				<span class="well well-lg key" id="59">;</span>
				<span class="well well-lg key" id="39">'</span>
			</div>
			<div class="row col-lg-12 keys-row">
				<span class="well well-lg key" id="122">z</span>
				<span class="well well-lg key" id="120">x</span>
				<span class="well well-lg key" id="99">c</span>
				<span class="well well-lg key" id="118">v</span>
				<span class="well well-lg key" id="98">b</span>
				<span class="well well-lg key" id="110">n</span>
				<span class="well well-lg key" id="109">m</span>
				<span class="well well-lg key" id="44">,</span>
				<span class="well well-lg key" id="46">.</span>
				<span class="well well-lg key" id="47">/</span>
			</div>
		</div>
		<div class="row col-lg-12 text-center keys-row">
			<div class="well well-lg key" id="32"> Space</div>
		</div>
	</div>
            
          
!
            
              * {
  margin: 0;
  padding: 0;	
}

#prompt-container {
  font-family: "Courier New", Courier, monospace;
  font-size: 24px;
  letter-spacing: 3px;
}

#yellow-block {
  position: absolute;
  margin-top: 10px;
  width: 15px;
  height: 15px;
  background-color: yellow;
}

.keyboard-container {
  margin-top: 200px;
}

#target-letter {
  font-size: 38px;  
}

.keys-row {
  margin-top: 40px;
  padding: 10px 0;
}

#feedback {
  font-size: 20px;
}
.glyphicon-ok {
  color: #1DA237
}

.glyphicon-remove {
  color : #CD2626
}
            
          
!
            
              //key event to make one keyboard appear and another disappear

//AFTER DOCUMENT LOADS:
$(document).ready(function () {

    //ARRAY CONTAINING SENTENCES 
    var sentences = [
        'ten ate neite ate nee enet ite ate inet ent eate',
        'Too ato too nOt enot one totA not anot tOO aNot',
        'oat itain oat tain nate eate tea anne inant nean',
        'itant eate anot eat nato inate eat anot tain eat',
        'nee ene ate ite tent tiet ent ine ene ete ene ate'
    ];

    var together = sentences.join(" ");
    //NUMBER OF WORDS IN SENTENCES ARRAY
    var togetherLen = together.split(" ").length;


    //VARIABLES TO KEEP TRACK OF SENTENCES INDEX, WHERE YELLOW-BLOCK IS ON PAGE, AND TIME
    var sLength = sentences.length;
    var currentS = 0;
    var count = 0;
    var lettersOfS;
    var numberOfMistakes = 0;
    var initialTime = Date.now();
    var endTime;
    var wps;
    var wpm;

    //VARIABLE DECLARATIONS AND SETTING INITIAL VISIBILITY RULES FOR BOTH KEYBOARDS
    var upper = "#keyboard-upper-container";
    var lower = "#keyboard-lower-container";
    var sentenceId = "#sentence";
    $(upper).hide();
    $(lower).show();

    //TOGGLES BETWEEN UPPER AND LOWER IF SHIFT KEY IS PRESSED
    $(document).keydown(function (key) {
        if (key.keyCode === 16) {
            $(upper).show();
            $(lower).hide();
        }
    });

    $(document).keyup(function (key) {
        if (key.keyCode === 16) {
            $(lower).show();
            $(upper).hide();
        }
    });

    //HIGHLIGHTS AND UNHIGHLIGHTS THE KEY THAT IS BEING PRESSED 
    $(document).keypress(function (key) {
        var grabKey = key.which;
        var keyId = "#" + grabKey.toString();
        $(keyId).css("background-color", "#ffff99");
        $(document).keyup(function (grabKey) {
            $(keyId).css({ "background-color": "" })
        })
    });

    //DISPLAYS FIRST SENTENCE AND TARGET LETTER
    $(sentenceId).append("<p>" + sentences[currentS] + "</p>");
    $("#target-letter").append("<h1>" + 't' + "</h1>");   

    //TRACKS AND DISPLAYS FEEDBACK SYMBOLS(RIGHT AND WRONG KEYS)
    //TRACKS AND DISPLAYS SENTENCES IN THE SENTENCES ARRAY
    //TRACKS AND DISPLAYS NEXT LETTER UNDERNEATH SENTENCE AND FEEDBACK DIVS
    $(document).keypress(function (key) {
        var lettersOfS = sentences[currentS].split("");
        var numberOfWords = togetherLen
        //TESTS IF THE COUNT VARIABLE IS THE LENGTH OF THE CURRENT SENTENCE
        if (count >= (lettersOfS.length - 1)) { 
           currentS += 1
           //IF CURRENT SENTENCE IS LESS THAN THE TOTAL SENTENCES
           //MOVE TO NEXT SENTENCE AND CONTINUE TO DISPLAY YELLOW-BLOCK, FEEDBACK, AND NEXT LETTER
           if (currentS < sentences.length) {
            $(sentenceId + " p").remove();
            $("#yellow-block").animate({
                left: "17px"
            }, 10);
            $("#feedback div").remove();
            lettersOfS = sentences[currentS].split("");
            count = 0;
            $(sentenceId).append("<p>" + sentences[currentS] + "</p>")
            $("#target-letter h1").remove();
            $("#target-letter").append("<h1>" + lettersOfS[count] + "</h1>")
            //OTHERWISE GAME IS OVER. DISPLAY RESULTS AND PROMPT TO PLAY AGAIN
           } else {
               $("#target-letter h1").remove();
               endTime = Date.now();
               timeSec = Math.floor((endTime - initialTime) / 1000);
               wpm = Math.floor((numberOfWords/ (Math.floor(timeSec) / 60) - (2 * numberOfMistakes)));
               alert("You typed " + wpm + " words per minute.");
               setTimeout(function () {
                   var stank = prompt("Type 'Yes' to play again");
                   if (stank.toUpperCase() === "YES") {
                       location.reload();
                   } 
               }, 2000);
           }
          //OR IF THE KEY CODE OF THE KEY PRESSED === KEY CODE OF THE CURRENT LETTER IN THE SENTENCE
          //MOVE TO NEXT LETTER, FEEDBACK INDICATES CORRECT, MOVES FOWARD
        } else if (key.charCode === sentences[currentS].charCodeAt(count)) {
            $("#yellow-block").animate({
            left: "+=17.5px"
            }, 10);
            $("<div></div>").addClass("glyphicon glyphicon-ok").appendTo($("#feedback"));
            count += 1;
            $("#target-letter h1").remove();
            $("#target-letter").append("<h1>" + lettersOfS[count] + "</h1>")
          //OR IF KEY CODE OF CURRENT LETTER DOES !== KEY CODE OF THE CURRENT LETTER IN THE SENTENCE
          //MOVE TO NEXT LETTER, FEED BACK INDICATES INCORRECT, MOVES FOWARD
        } else if (key.charCode !== sentences[currentS].charCodeAt(0)) {
            $("#yellow-block").animate({
            left: "+=17.5px"
            }, 10);
            $("<div></div>").addClass("glyphicon glyphicon-remove").appendTo($("#feedback"));
            count += 1;
            $("#target-letter h1").remove();
            $("#target-letter").append("<h1>" + lettersOfS[count] + "</h1>")
            numberOfMistakes += 1;
        }

    })
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console