Computer Choice part2 error. Help


#1



https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#


SyntaxError: missing before statement


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

if (computerChoice<=0.33){
    computerChoice="rock";
    }
    
    else if (computerChoice>=0.34){
        computerChoice="paper";
    }
    
    else (computerChoice>=0.67){
        computerChoice="scissors";
    }
    
    console.log("Computer is" + computerChoice);


#2

What lesson are you on and what is your question?


#3

Computer Choice Part2


#4

Hi the else statement doesn't take any condition.


#5

means.. ? Please ellaborate


#6

your else if condition is wrong. Currently, it is either rock or paper, i would the reverse, i would below or equal to .66 to be paper, now numbers lower then .66 are then paper, if the numbers are equal or lower then .33 will be rock (if the if condition is true, else if will not run)

Else can't have any conditions at all, it is everything else, remove the condition from else

currently you have:

else(condition){}

remove the condition all together:

else {}

#7

This did worked but with a wrong answer .. When I enter "rock " then is displays computer is rock


#8

The else statement will run if anything that wasn't specified in the if statement(s) is imputed. This means that you don't need to give a condition or reason to run the else statement because the code will automatically run it.
Does that make sense?


#9

Oops, try again.
Did you make one of your ranges end at .66?

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

if (computerChoice<=0.33){
computerChoice="rock";
}

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

else {
    computerChoice="scissors";
}

#10

yes .. got it . But now I have stucked into another one..


#11

(computerChoice>=0.34)//wrong
(computerChoice>=0.66)//right

@rohit_786


#12

Thanks a lot !! It worked man. Good..!!


#13

like i already said, your else if condition is wrong, i might have use paper somewhere where it should be rock, fixed that now. Your if statement will make sure that all numbers equal or lesser then .33 become rock, then the numbers lower or equal then .66 should become paper. If the number is .33 or lower, if will run, else if will not run in that case, so you can just check if the numbers are equal or lower then .66, and then all the remaining numbers will be run at the else statement, turning computerChoice into scissors


#14

still wrong, should:

(computerChoice<=0.66)

otherwise the numbers between .33 and .66 are nothing, as i just explained in my answer. Now the numbers between .33 and .66 will be paper, and everything from .67 till 1 will be paper, thanks to your else statement


#15

Thanks a lot .. Bro ... I need to go through it once again.


#16

opps typo......
actually i wanna say that
but....
thank u @stetim94 :slight_smile:

sorry @rohit_786