Advertisement
Guest User

timer and submit button functions

a guest
May 1st, 2020
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const testWrapper = document.querySelector(".test-wrapper").innerHTML;
  2. const testArea = document.querySelector("#test-area").innerHTML;
  3. const originText = document.querySelector("#origin-text p").innerHTML;
  4. const resetButton = document.querySelector("#reset").innerHTML;
  5. const theTimer = document.querySelector(".timer").innerHTML;
  6. var seconds;
  7. var minutes;
  8. var hundreths;
  9. // Add leading zero to numbers 9 or below (purely for aesthetics):
  10. submitButtonClicked=true;
  11. /*
  12.   -if the user types, set submitButtonClicked to false to start the timer
  13.   -if the user clicks submit, set submitButtonClicked to false
  14. */
  15.  
  16. function timer() {
  17.   var num = 0;
  18.   //continue timer until user clicks submit button
  19.   //will code submit button after I can get this timer to work
  20.   while(submitButtonClicked===false){
  21.   /*
  22.   while hundreths is less than a second:
  23.     -if hundreths is less than 10 or if the number of milliseconds adds up perfectly the number of seconds , add a trailing zero in front of it
  24.     -if hundreths is at least 10 but less than one second, just display the hundreths
  25.     -if hundreths is equal to one second
  26.       #1. increment seconds
  27.       #2. reset hundreths to zero so that hundreths is never greater than the
  28.       amount it takes to be as large as one second. This makes sure the clock
  29.       is readable and that
  30.     -always increment hundreths in every if statements body
  31.   */
  32.    if (hundreths < 10 || num % seconds === 0){
  33.     setInterval(function addTime(){
  34.       document.getElementById("timer").innerHTML = `00:00:0 + ${hundreths}`;
  35.     }, 10);
  36.     hundreths++;
  37.     num++;
  38.     }else if (hundreths === 10){
  39.       //if hundreths of seconds is greater than 100, increase seconds and reset hundreths to zero
  40.       setInterval(function addTime(){
  41.       document.getElementById("timer").innerHTML = `00:00: + ${hundreths}`;
  42.       hundreths = 0
  43.       num++;
  44.     }, 10);
  45.       if (hundreths === 100){
  46.       seconds++
  47.       hundreths=0;
  48.       }
  49.     }
  50.     /*
  51.       while seconds is less than one minute:
  52.         -if seconds is less than 10, add a trailing zero in front of seconds and increment
  53.         -if seconds is at least 10, but less than one minute, just display the seconds
  54.        
  55.         UPDATE!!! I am confused on where to go after one minute and I am having trouble putting that into code!!! It doesn't seem like an even pattern!!!
  56.     */
  57.   }
  58. // Run a standard minute/second/hundredths timer:
  59.  
  60.  
  61. // Start the timer:
  62. function startTimer(){
  63.   //start timer as soon as user types something in, regardless of what is typed in
  64.   document.querySelector("#test-area").addEventListener("type", timer(theTimer));
  65. }
  66.  
  67. // Reset everything:
  68. function resetTimer() {
  69.   hundreths=0;
  70.   seconds=0;
  71.   minutes=0;
  72. }
  73.  
  74. //Event Listeners to measure if someone is typing!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement