Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda