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

128
Visualizações
Javascript problem with logical operations and greater than

Hello I am learning JavaScript and I have a question, I have made simple algorithm to check "if something". My question is about this line if(dolphins && koalas > minimumScore). It seems to me illogical, but it works in a way I want. Because in beginning I wanted to check if dolphins or koalas > minimumScore (So I used ||). But when I set both teams to value under 100 it kept going to the next if block and else if but not to else statement. So I had to use && and it works, it goes to the else if both teams are under 100 and goes to the next 'if' when at least one team is higher than 100.

let dolphins = 11;
let koalas = 11
const minimumScore = 100

if(dolphins && koalas > minimumScore){
    if(koalas > dolphins){
        console.log(`Koalas won! {$koalas}`)
    } else if(koalas===dolphins){
        console.log('draw')
    } else {
        console.log('dolphins won!')
    }
} else{
    console.log('no team won')
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

So (dolphins && koalas > minimumScore) is not checking if dolphins is greater than minimumScore and koalas is greater than minimum score. It is checking if dolphins is "truthy" and if koalas is greater than minimumScore. if you want to check that one or the other are greater than minimum score you must write.

(dolphins > minimumScore || koalas > minimumScore)

more about truthy values https://developer.mozilla.org/en-US/docs/Glossary/Truthy

about 4 years ago · Juan Pablo Isaza Relatório

0

that if is not written like this, it is usually written like this:

if (koalas > mininumScore && dolphins > mininumScore)
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