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
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>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.