Whats Wrong with my code?


#1

Im Confused here lol :laughing:

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

var computerChoice = Math.random()
console.log(computerChoice);

if(computerChoice<=0.3){
 computerChoice = console.log("Paper");   
}
if else(computerChoice>0.3 && computerchoice<0.6){
 computerChoice = console.log("Rock");   
}

 else{
 computerChoice = console.log("scissors");
}

#3

Hey @amanuel2,

It's supposed to be else if, not if else here:

Also, computerChoice is not supposed to change into a console.log, but a string. Take away the console.logs in everything here:

:smiley:


#4

Well the second one i had but changed if it might worked but the first one my bad. I was connecting it to Java. Thats the struggle when you know too many languages.. :weary:


#5

In Java it is else if also, not if else.


#6

its if else. Im not talking about javascript im talking about actual Java


#7

Would suggest putting it in the Java section then...

And I searched it up. It seems as if it is else if for Java, too.


#8

No the code was javascript, but like when i wrote the javascript program i accidently used else if whitch we normally use in java to use in javascript. If you dont get it just move on with life.


#9

Yes, in Java it is else if.

Documentation -> https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html

I don't want to be mean, but seriously, it would not make any sense to use if else in any language. It would complicate logical grammar of the language.


#10

I was reading the same thing :laughing:


#11

Slow day dont judge me! :laughing:


#12

It's fine :smile:

Remember about taking breaks while working / studying!


#13

Yea i should do that more often.