Advertisement
Guest User

JS 2500

a guest
Dec 13th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var temp = document.querySelector('.time');
  2.      var button = document.querySelector("button");
  3.      var box = document.querySelector(".box");
  4.     var words = document.querySelector(".words");
  5.     var timerDiv = document.querySelector(".time");
  6.      var scoreDiv = document.querySelector(".score");
  7.      var outer = document.querySelector(".outerWrap");
  8.      var man = document.getElementById("man");
  9.     var points = 0;
  10.     var spans;
  11.      var typed;
  12.      var pos=-130;
  13.      var seconds =60;
  14.      var modal = document.querySelector(".modal");
  15.      var content = document.querySelector(".content");
  16.     var trigger = document.querySelector(".trigger");
  17.     var closeButton = document.querySelector(".close-button");
  18. function loader(){
  19.    
  20.     outer.style.display='none';
  21. }
  22.    
  23.      function countdown() {
  24.         points = 0;
  25.        
  26.      
  27.         var timer = setInterval(function(){
  28.             button.disabled = true;
  29.            seconds--;
  30.            temp.innerHTML = seconds;
  31.            if (seconds === 0) {
  32.                
  33.                scoreDiv.innerHTML = "0";
  34.                words.innerHTML = "";
  35.                button.disabled = false;
  36.                var m = setInterval(move,60);
  37.                
  38.                content.innerHTML="Your score is "+points;
  39.               function move(){
  40.                box.style.visibility='hidden';
  41.                pos=pos+10;
  42.                man.style.left = pos+'px';
  43.                if (pos >950){
  44.                 clearInterval(m);
  45.            
  46.          }
  47.         }
  48.                clearInterval(timer);
  49.                move();
  50.                seconds = 60;
  51.                timerDiv.innerHTML = "60";
  52.                button.disabled = false;
  53.            }
  54.         }, 1000);
  55.      }
  56.  
  57.      function random() {
  58.     words.innerHTML = "";
  59.     var random = Math.floor(Math.random()*list.length);
  60.    
  61.     var wordArray = list[random].split("");
  62.     for (var i = 0; i < wordArray.length; i++) { //building the words with spans around the letters
  63.         var span = document.createElement("span");
  64.         span.classList.add("span");
  65.         span.innerHTML = wordArray[i];
  66.         words.appendChild(span);
  67.     }
  68.     spans = document.querySelectorAll(".span");
  69. }
  70.  
  71.  
  72. const list = ['EXERCISE','EXERTION','EXERCISING', 'PRACTICE','GYM','TRAINING','TRAINER','MUSCLE','MEETING','ADJUST','ADJUSTING','ADJUSTMENT','RESTRUCTURING','MOVEMENT','CRANKING','RESTRUCTURE',
  73. 'REGULATION','READJUSTMENT','SMACK','CORRECTION','SLIDE','SOLO', 'SPECULATION','SPIRIT','SPORTS', 'SPORTSMANSHIP', 'SQUAD', 'SQUAT', 'STABILITY', 'STAMINA', 'STATISTICS', 'STEPPER', 'STRATEGY', 'STREAK', 'STRENGTH', 'STRETCHING', 'STRIDE', 'STRONG',  'SUPINATION', 'SUPPORT','SUSPENSION', 'SWIMMING', 'SYMPTOMS',
  74. 'TACKLE', 'TARGETS', 'TEAM', 'TEAMMATE', 'TECHNICAL', 'TENNIS', 'TEST', 'THERAPEUTIC', 'THERAPY', 'TIMEOUT', 'TIMING', 'TONE', 'TORSO', 'TOURNAMENT', 'TRAINER', 'TRAINING', 'TRANSFORM', 'TRANSFORMATION', 'TREADMILL',
  75. 'UNBELIEVABLE', 'UNUSUAL', 'USUAL','VACCINATION', 'VALIANT', 'VICTORY', 'VIOLATION', 'VITAMINS'];
  76.  
  77.  
  78.     button.addEventListener("click", function(e){
  79.         outer.style.display='block';
  80.           var i = setInterval(moveRight,80);
  81.         function moveRight() {
  82.             man.style.display='block';
  83.             pos=pos+10;
  84.            if (pos >120){
  85.            clearInterval(i);
  86.         box.style.display='block';
  87.         countdown();
  88.     }
  89.             man.style.left = pos+'px'; // pseudo-property code: Move right by 10px
  90.            
  91.         }
  92.         var modal=document.querySelector(".modal");
  93.         modal.style.display='none';
  94.          
  95.          
  96.           random();
  97.          
  98.         button.disabled = true;
  99.     });
  100.  
  101.  
  102.     function typing(e) {
  103.             typed = String.fromCharCode(e.which);
  104.             for (var i = 0; i < spans.length; i++) {
  105.                 if (spans[i].innerHTML === typed) { // if typed letter is the one from the word
  106.                     if (spans[i].classList.contains("bg")) { // if it already has class with the bacground color then check the next one
  107.                         continue;
  108.                     } else if (spans[i].classList.contains("bg") === false && spans[i-1] === undefined || spans[i-1].classList.contains("bg") !== false ) { // if it dont have class, if it is not first letter or if the letter before it dont have class (this is done to avoid marking the letters who are not in order for being checked, for example if you have two "A"s so to avoid marking both of them if the first one is at the index 0 and second at index 5 for example)
  109.                         spans[i].classList.add("bg");
  110.                         break;
  111.                     }
  112.                 }
  113.             }
  114.             var checker = 0;
  115.             for (var j = 0; j < spans.length; j++) { //checking if all the letters are typed
  116.                 if (spans[j].className === "span bg") {
  117.                     checker++;
  118.                 }
  119.                 if (checker === spans.length) { // if so, animate the words with animate.css class
  120.            
  121.                     words.classList.add("animated");
  122.                       words.classList.add("fadeOut");
  123.                       setTimeout(display,100);
  124.                       function display(){
  125.                         box.style.display = 'none';
  126.                       }
  127.                      
  128.                      
  129.                      
  130.                     points++; // increment the points
  131.                     scoreDiv.innerHTML = points; //add points to the points div
  132.                     document.removeEventListener("keydown", typing, false);
  133.                     setTimeout(function(){
  134.                         words.className = "words"; // restart the classes
  135.                           random(); // give another word
  136.                          
  137.                           box.style.display='block';
  138.                         document.addEventListener("keydown", typing, false);
  139.                     }, 400);
  140.                 }
  141.  
  142.             }
  143.     }
  144.  
  145.     document.addEventListener("keydown", typing, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement