Please add comments to my code. ----------------------------------------------------- let currProblem = 1; let currScore = 0; let answer;    function updateScoreAndQuestion() {     let problem = document.getElementsByClassName("currentProblem")[0];     problem.innerText = currProblem.toString();     let score = document.getElementsByClassName("currentScore")[0];     score.innerText = currScore.toString();     if(currProblem <= 10) {         newProblem();     } else {         let hide = document.querySelectorAll('.show-hide');                  hide.forEach(element => {             element.style.display = "none";             currProblem = 10;             problem.innerText = currProblem.toString();         })     } }   function start() {     let answers = document.querySelectorAll("li");     answers.forEach(element => {         element.addEventListener("click", event => {             let choice = element.innerText;             if(choice.toString() === answer.toString()) {                 currScore++;             }                          currProblem++;                          updateScoreAndQuestion();         })     }); }     function newProblem() {          let left_operand = Math.floor(Math.random()*Math.floor(10));     let right_operand = Math.floor(Math.random()*Math.floor(10));     answer = left_operand * right_operand;     updateDisplayProblem([left_operand, right_operand]); }       function updateDisplayProblem(operands) {     let displayProblem = document.getElementsByClassName("expression show-hide")[0];     displayProblem.innerText = operands[0] + " * " + operands[1];     let answers = document.querySelectorAll("li");     let possibleAnswers = [];     possibleAnswers.push(operands[0] * operands[1]);     while(possibleAnswers.length < 4) {         let choice = Math.floor(Math.random()*Math.floor(81));         if(!possibleAnswers.includes(choice)) {             possibleAnswers.push(choice);         }     }     possibleAnswers = possibleAnswers.sort(function (a, b) {return Math.random() - 0.5});     for(let i = 0; i < answers.length; i++) {         answers[i].innerText = possibleAnswers[i];     } }     document.addEventListener("DOMContentLoaded", event => {     start();     newProblem();      let startOver = document.getElementById("btnStartOver");     // resets score and sets problem to 1     startOver.addEventListener("click", event => {         currProblem = 1;         currScore = 0;         // updates score and gives out new question         updateScoreAndQuestion();         newProblem();         let show = document.querySelectorAll('.show-hide');                  show.forEach(element => {             element.style.display = "block";         });     }); })

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please add comments to my code.
-----------------------------------------------------

let currProblem = 1;
let currScore = 0;
let answer; 

 


function updateScoreAndQuestion() {
    let problem = document.getElementsByClassName("currentProblem")[0];
    problem.innerText = currProblem.toString();

    let score = document.getElementsByClassName("currentScore")[0];
    score.innerText = currScore.toString();

    if(currProblem <= 10) {
        newProblem();
    } else {
        let hide = document.querySelectorAll('.show-hide');
        
        hide.forEach(element => {
            element.style.display = "none";
            currProblem = 10;
            problem.innerText = currProblem.toString();
        })
    }
}

 


function start() {
    let answers = document.querySelectorAll("li");

    answers.forEach(element => {
        element.addEventListener("click", event => {
            let choice = element.innerText;

            if(choice.toString() === answer.toString()) {
                currScore++;
            }

            
            currProblem++;
            
            updateScoreAndQuestion();
        })
    });
}

 

 


function newProblem() {
    
    let left_operand = Math.floor(Math.random()*Math.floor(10));
    let right_operand = Math.floor(Math.random()*Math.floor(10));
    answer = left_operand * right_operand;
    updateDisplayProblem([left_operand, right_operand]);
}

 

 

 

function updateDisplayProblem(operands) {
    let displayProblem = document.getElementsByClassName("expression show-hide")[0];
    displayProblem.innerText = operands[0] + " * " + operands[1];

    let answers = document.querySelectorAll("li");

    let possibleAnswers = [];
    possibleAnswers.push(operands[0] * operands[1]);

    while(possibleAnswers.length < 4) {
        let choice = Math.floor(Math.random()*Math.floor(81));
        if(!possibleAnswers.includes(choice)) {
            possibleAnswers.push(choice);
        }
    }

    possibleAnswers = possibleAnswers.sort(function (a, b) {return Math.random() - 0.5});

    for(let i = 0; i < answers.length; i++) {
        answers[i].innerText = possibleAnswers[i];
    }
}

 

 


document.addEventListener("DOMContentLoaded", event => {
    start();
    newProblem(); 

    let startOver = document.getElementById("btnStartOver");

    // resets score and sets problem to 1
    startOver.addEventListener("click", event => {
        currProblem = 1;
        currScore = 0;

        // updates score and gives out new question
        updateScoreAndQuestion();
        newProblem();

        let show = document.querySelectorAll('.show-hide');
        
        show.forEach(element => {
            element.style.display = "block";
        });
    });
})

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Database connectivity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education