vendredi 1 février 2019

How to combine multiple variables within an if statement [on hold]

I'm new to JavaScript and am trying to get the following code to work. I think I have some syntax issues somewhere.

In this code snippet I'm setting all the scores 1~5 to be zero. In another part of my code (that's not here), the scores will increase.

I'm having a problem with line 9 ~ 12 in this code I wrote. I'm trying to say that

if

score1 is greater than equal to 1 and

score2 is greater than equal to 1 and

score3 is greater than equal to 1 and

score4 is greater than equal to 1 and

score5 is greater than equal to 1

then userWin becomes true

score1, score2, score3, score4, score5 all have to be greater than or equal to 1, all at the same time in order for userWin to become true.

Any suggestions would be appreciated, Thanks!

var score1 = 0;
var score2 = 0;
var score3 = 0;
var score4 = 0;
var score5 = 0;

var userWin = false;

if (score1 >= 1 && score2 >= 1 &&
  score3 >= 1 && score4 >= 1 &&
  score5 >= 1) {
  userWin === true;
}

console.log(userWin);

Aucun commentaire:

Enregistrer un commentaire