I have one webpage ,when loading the page it asks some questions if all the questions are correct only then it displays the body part otherwise the question will not allow next question or it should not displays the body part , please help me to fix this issue...
<!DOCTYPE html>
<html>
<head>
<title>Special-Wishes </title>
<script>
let q1=prompt("what is your name...?"); //if the q1 answer is wrong it should not display the body content
if(q1 == "John" || "JOHN" ){
let q2=prompt("what's your nick name...?");
if(q2=="blabla"){
alert("welcome to the page");
}
}
</script>
</head>
<body>
<h1>My body section</h1>
</body>
The reason why it is still asking the next question is due to your if statement logic
if(q1 == "John" || "JOHN" ) should be if(q1 == "John" || q1 == "JOHN" )
An even easier way of doing this would be if(q1.toUpperCase() == "JOHN")
In order to not display the body, you want to either remove it, or make it hidden. This can be done in a else block after your if statement
Remove: document.body.remove();
Hide: document.body.style.display = "none";
Use document.body.style.display = "none" when condition not matched
let q1 = prompt("what is your name...?"); //if the q1 answer is wrong it should not display the body content
if (q1 == "John") {
let q2 = prompt("what's your nick name...?");
if (q2 == "blabla") {
alert("welcome to the page");
} else {
document.body.style.display = "none"
}
} else {
document.body.style.display = "none"
}
<body>
<h1>My body section</h1>
</body>