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

104
Vistas
Mostrar el segundo mensaje si el primer mensaje no es VERDADERO

Tengo un problema cuando trato de mostrar un mensaje nuevo, uso loop pero mostrará mi mensaje. Aquí está mi código y realmente necesito ayuda

 <body> <p id="age" style="font-weight: bold"></p> <button onclick=" notify()">Try it</button> <script> function notify(){ var age = document.getElementById("age").value; var age = prompt("Enter Your birth year:");// This is the first prompt const year = new Date().getFullYear(); if (age != null) { document.getElementById("age").innerHTML = "Your " + age + " is so beautiful"; // If user enter birth year < current year will display this } do { age = prompt("Re-enter your birth year:"); // Ortherwise, this will display and they need to enter until birth year < current year } while (age > year && age != null); var tuoi = year - age;// This is just calculate user'age, for example if the user enter 2000 will display user'age is 22 document.getElementById("age").innerHTML = "Tuổi " + tuoi + " này đẹp đó"; } </script> </body>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

su código tiene varios problemas y hace algunas cosas que no tienen mucho sentido para mí, pero creo que quiere algo como esto:

 <body> <p id="age" style="font-weight: bold"></p> <button onclick=" notify()">Try it</button> <script> function notify() { const year = new Date().getFullYear(); var birth_year = parseInt(prompt("Enter Your birth year:")); // This is the first prompt if (!isNaN(birth_year) && birth_year < year) { document.getElementById("age").innerHTML = "Your " + birth_year + " is so beautiful"; // If user enter birth year < current year will display this } else { do { birth_year = parseInt(prompt("Enter Your birth year:")); // Ortherwise, this will display and they need to enter until birth year < current year } while (isNaN(parseInt(birth_year)) || birth_year >= year); var tuoi = year - age; // This is just calculate user'age, for example if the user enter 2000 will display user'age is 22 document.getElementById("age").innerHTML = "Tuổi " + birth_year + " này đẹp đó"; } } </script> </body>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Simplemente olvidó una parte de su condición if.

Cambie if (age != null) a if (age != null && age < year) y funcionará como lo espera. No olvide el caso si edad == año.

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