Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!