Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: Code: <!DOCTYPE html> <html> <head> <title>Answer</title> </head> <bod

ID: 3548832 • Letter: Q

Question

Question:



Code:


<!DOCTYPE html>
<html>

<head>
    <title>Answer</title>
</head>

<body>

    <script>
    
        var num1=((Math.random()*100)+20).toFixed(0);
        var num2=((Math.random()*98)+20).toFixed(0);
        var total=num1+num2;
        setTimeout("alertMsg()",3000);
        var decision=confirm("Are you ready to answer?");;

        if(decision==true)
        {
        
         document.write("What is the answer to:"+num1+"+"+num2);
        
        }
        
        else
        {
          
        }
        
        var ans=document.frm.answer.value;
        
        function check_ans()
        {
            if(ans==total)
            {
            
            }
            
            else if(ans!=total)
            {
                alert("Sorry! Wrong answer");
            }
        }
        
        
    </script>

    <form name="frm">
    
        <p>Search for: <input type ="number" name="answer"/>
        <input type="submit" name="btnsubmit" value="Submit Answer"/></p>
    
    </form>
    
</body>

</html>


Please my correct my code, using comment explain.
thank

This is a math quiz program whereby the user has 10 seconds to answer each question. Firstly, ask the user whether they are ready to answer the question. If they click "OK", then give them 2 random numbers from 20 to 100 to total. Next, start a timer for 10 seconds. Use the setTimeout() function. Use a form as shown below to get the answer from the user. If the user's answer is correct, display an alert "Well done" and stop the timer. If the user's answer is wrong, display an alert "Sorry! Wrong answer" and stop the timer. Stop the timer using the clearTimeout() function. If the user did not answer the question within 10 seconds, show "Sorry!! Time is up!" on the browser. What is the answer to : 60 + 21 Sony!! Tune is up! What is the answer to : 32 + 93

Explanation / Answer

Code:


<!DOCTYPE html>
<html>

<head>
<title>Answer</title>
</head>

<body>

<script>

var num1=((Math.random()*80)+20).toFixed(0); //Math.random()*80 will choose from 0-80
var num2=((Math.random()*80)+20).toFixed(0); // number should be from 20-100 so add 20

var total=num1+num2;
var decision=confirm("Are you ready to answer?");;

if(decision==true)
{
setTimeout("alertMsg()",10000); // timer should start only after cliking yes

// 10000=10*1000 = 10 seconds
document.write("What is the answer to:"+num1+"+"+num2);

}

else
{

}

var ans=document.frm.answer.value;

function check_ans()
{
if(ans==total)
{
clearTimeout(); //timeout should be cleared if correct answer
}

else if(ans!=total)
{
alert("Sorry! Wrong answer");
}
}


</script>

<form name="frm">

<p>Search for: <input type ="number" name="answer"/>
<input type="submit" name="btnsubmit" value="Submit Answer"/></p>

</form>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote