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

227
Vistas
How do I combine boolean with if else statement?

I am dealing with the question of:

Create a Java Script control structure using if..else statement. Declare one variable and use Boolean condition to determine whether the condition is true or false. If the first condition evaluates to true, then the program will run the first block of code. Otherwise, it will run the else block. Show your output using the given condition.

{

if weather is equal to thunderstorm;

 then display “Stay at home”;

else

 then display “Happy Journey”;

}

Is it possible to show the output in html? How can I fix my code to show the output? It is not working currently.

This is my code:

<body>
  <p id="demo"></p>
  <script>
    boolean thunderstorm = true;
    if (thunderstorm) {
      document.getElementById("demo").innerHTML = "Stay at home";
    } else {
      document.getElementById("demo").innerHTML = "Happy Journey";
    }
  </script>
</body>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Welcome to SO :)

If you check your developer tools and look at the console, you should see an error like "message": "Uncaught SyntaxError: Unexpected identifier",. In this case that is coming from your usage of "boolean". In JavaScript we don't have to declare variable types like that, instead you would use const, let or var to declare a variable, like on my example below.

const thunderstorm = true;
if (thunderstorm){
    document.getElementById("demo").innerHTML ="Stay at home";
} else {
    document.getElementById("demo").innerHTML ="Happy Journey";
}
<p id="demo"></p>

With JavaScript the type of a variable is not as strict as in some other languages. To quote MDN:

JavaScript is a loosely typed and dynamic language. Variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned (and re-assigned) values of all types

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures

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