Jave Script - Create a Kumon math exercise for youth (if, random, while loop)
Randomly output a math addition exercises and ask use input and use if statement to output feedbacks.
Use while loop to continue to test the students until the students say "no" to your question " do you still want to continue the exercise?"
<!DOCTYPE html>
<html>
<script>
while(true){
let n1=Math.floor(Math.random() * Math.floor(99));
let n2=Math.floor(Math.random() * Math.floor(99));
userInput=prompt("Enter "+n1+" + "+n2+" = or no for exist");
if(userInput=="no" || userInput=="NO"){
break;
}
value=parseInt(userInput);
if(n1+n2==value){
document.write("Correct Answer!<br/>");
}else{
document.write("Wrong Answer!<br/>");
}
}
</script>
</html>
#output:
Get Answers For Free
Most questions answered within 1 hours.