Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
How to stop showing the webpage after entering wrong answers?

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>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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";

about 4 years ago · Juan Pablo Isaza Denunciar

0

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>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda