Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const testWrapper = document.querySelector(".test-wrapper").innerHTML;
- const testArea = document.querySelector("#test-area").innerHTML;
- const originText = document.querySelector("#origin-text p").innerHTML;
- const resetButton = document.querySelector("#reset").innerHTML;
- const theTimer = document.querySelector(".timer").innerHTML;
- var seconds;
- var minutes;
- var hundreths;
- // Add leading zero to numbers 9 or below (purely for aesthetics):
- submitButtonClicked=true;
- /*
- -if the user types, set submitButtonClicked to false to start the timer
- -if the user clicks submit, set submitButtonClicked to false
- */
- function timer() {
- var num = 0;
- //continue timer until user clicks submit button
- //will code submit button after I can get this timer to work
- while(submitButtonClicked===false){
- /*
- while hundreths is less than a second:
- -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
- -if hundreths is at least 10 but less than one second, just display the hundreths
- -if hundreths is equal to one second
- #1. increment seconds
- #2. reset hundreths to zero so that hundreths is never greater than the
- amount it takes to be as large as one second. This makes sure the clock
- is readable and that
- -always increment hundreths in every if statements body
- */
- if (hundreths < 10 || num % seconds === 0){
- setInterval(function addTime(){
- document.getElementById("timer").innerHTML = `00:00:0 + ${hundreths}`;
- }, 10);
- hundreths++;
- num++;
- }else if (hundreths === 10){
- //if hundreths of seconds is greater than 100, increase seconds and reset hundreths to zero
- setInterval(function addTime(){
- document.getElementById("timer").innerHTML = `00:00: + ${hundreths}`;
- hundreths = 0
- num++;
- }, 10);
- if (hundreths === 100){
- seconds++
- hundreths=0;
- }
- }
- /*
- while seconds is less than one minute:
- -if seconds is less than 10, add a trailing zero in front of seconds and increment
- -if seconds is at least 10, but less than one minute, just display the seconds
- 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!!!
- */
- }
- // Run a standard minute/second/hundredths timer:
- // Start the timer:
- function startTimer(){
- //start timer as soon as user types something in, regardless of what is typed in
- document.querySelector("#test-area").addEventListener("type", timer(theTimer));
- }
- // Reset everything:
- function resetTimer() {
- hundreths=0;
- seconds=0;
- minutes=0;
- }
- //Event Listeners to measure if someone is typing!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement