Guest User

Untitled

a guest
May 27th, 2019
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.91 KB | None | 0 0
  1. <span id='left'></span><span id='cursor'>T</span><span id='right'>he quick brown fox jumps over the lazy dog</span>
  2. <br><input/>
  3. <style>
  4.   span {
  5.     font-family: Monospace;
  6.   }
  7.   #cursor {
  8.     background: darkred;
  9.   }
  10. </style>
  11. <script>
  12.   const l  = document.querySelector('#left');
  13.   const c  = document.querySelector('#cursor');
  14.   const r  = document.querySelector('#right');
  15.   const tb = document.querySelector('input');
  16.  
  17.   tb.onkeydown = e => {
  18.     tb.value = "";
  19.     if (e.key != c.innerText) return;
  20.  
  21.     if (l.innerText == "") start = new Date();
  22.     l.innerText += c.innerText;
  23.  
  24.     if (r.innerText != "") {
  25.       const rest  = r.innerText
  26.       r.innerText = rest.substr(1);
  27.       c.innerText = rest[0];
  28.     } else {
  29.       const dt  = new Date() - start;
  30.       const wpm = Math.round((60 * 1000 / 5 * l.innerText.length) / dt);
  31.       alert("You typed " + wpm + " wpm!")
  32.     }
  33.   };
  34. </script>
Add Comment
Please, Sign In to add comment