Build "Rock, Paper, Scissors" 4/9


#1

Hey.

I had a trouble getting this thing working.
I had the following non-working code:

if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice >= 0.34 AND computerChoice  <= 0.67) {  ///////// CHECK THIS LINE OUT
	computerChoice = "paper";
} else {
	computerChoice = "scissors";}

It kept telling there was a syntax error.

Now, I know that I will probably know more about this in the next exercises AND that the logic implies that you don't have to ELSE IF computerChoice >= 0.34, but what confuses me is the syntax error.

So, how do you do multiple condition check?
Example please
if (computerChoice > this and computerChoice < that) does not work.
Thanx


#2

for the "/////////CHECK THIS LINE OUT" part, all you had to do was make computerChoice >= 0.66.


#3

yes, I got that.
But my question was actually, how to make multiple condition within single IF statement, like
IF (condition1 and condition 2) ...


#4

Instead of "And" you have to use "&" symbol and execute below code

else if(computerChoice >= 0.34 & computerChoice <= 0.67)
{
computerChoice = "paper";
}


#5

now, that is what I was looking for!!
thank you!


#6

Better use && which is the boolean operator AND. & means AND as well but for binary numbers e.g. 7&3 is 3 because

7: 111
3: 011
so the lines where they match are both 1 are:
3: 011

#7

Please read
comparison operator
assigment operator
logical operator
in
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators


#8

i sure will.
thanks haxor, thanks leonhard.


#9

can somebody verify my code? The system says I passed, but I ran the code five times and I kept getting "paper" as the "computerChoice" I don't consider that random. Here is my code:

var userChoice = prompt("Do you choose rock, paper or scissors");
var computerChoice = Math.random()

if ("computerChoice" <= 0.33) {
computerChoice="Rock";
}
else if ("computerChoice" >= 0.34 <= 0.66) {
computerChoice="Paper";
}
else {
computerChoice="Scissors";
};


#10

@dubsnstuff,

(computerChoice <= 0.33)
(in Human language: a condition using an expression with the less-equal-operator, comparing the variable =computerChoice= to the number Value 0.33 )

(computerChoice >= 0.34 && computerChoice <= 0.66)
concatenating 2 expressions with the logical-AND operator
the first expression using the relational greater-equal operator
the 2nd expression using the relational less-equal-operator

The IF ELSE-IF ELSE
could also be written as

//the purpose is
// replacing the **number Value** of VARIABLE =computerChoice= with a **string Value**
if (computerChoice <= 0.33) {
    computerChoice="Rock";
 }
 else if (computerChoice <= 0.66) {
    computerChoice="Paper";
 }
else {
    computerChoice="Scissors";
 } //do NOT use a semi-colon on an IF-statement-structure