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

176
Visualizações
ELIF - JavaScript - do/while loop in rock, paper, scissors - the while condition I'm using is making my head hurt

For some reason I can't wrap my head around this condition. Can someone please explain like I'm five?

I searched on here, read MDN documentation, but I feel like I'm missing something simple.

while (playerScore !== 5 && cpuScore !== 5)

So the && is saying that when one of these conditions evaluates to false, then the whole statement is false, correct? And the while loop continues as long as the condition is true, right?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

That's absolutely correct. The && operator (also known as an "AND" operator) means that both parts of the statement need to be true for the whole statement to be true. Otherwise, the whole statement is false.

So as long as neither the player score and the CPU score are equal to 5 (meaning either one of them is either less than or greater than 5), the while loop will continue again and again.

The confusion is completely understandable, especially with the existence of the ! operators (also known as "NOT" operators).

Whenever I get confused with crafting statements like these, I try to break them down into the smallest chunks possible. With this statement, I would start with understanding the first half of the expression (playerScore !== 5), then move to the second half (cpuScore !== 5), and finally combine the two.

I hope that helps clear things up!

about 4 years ago · Juan Pablo Isaza Relatório

0

(playerScore !== 5 && cpuScore !== 5) means that if the playerScore is not equal to the number 5 and the cpuScore is not equal to the number five then the operation will continue.

So in order for your while loop to continue both playerScore and cpuScore must both not equal 5 at the same time.

!= means not equal !== means strictly not equal - this is type related && means and (both conditions must be true for the whole statement to be true)

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