How do I loop back to the prompt question if the user enters the wrong answer and I want the question to repeat until they get the correct answer?
<html>
<head>
<script>
</script>
<title> Javascript program</title>
</head>
<body>
<script>
var company = (prompt("What the name of the company that developed the javascript language?", ""));
if (company == 'netscape') {
alert("correct answer!");
} else {
alert("wrong answer");
}
</script>
</body>
</html>
You can wrap your code in a function and call self on incorrect value.
var max_count = 5;
function showConfirm() {
var company = (prompt("What the name of the company that developed the javascript language?", ""));
if (company == 'netscape') {
alert("correct answer!");
} else {
alert("wrong answer");
// to limit user for limited count
if (--max_count > 0)
showConfirm()
}
}
showConfirm();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With