Whats wrong about my code?


#1

please help me

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

console.log(computerChoice);

if (computerChoice <0.34) {
console.log(computerChoice);
computerChoice("rock");
}

else if (computerChoice <0.67) {
console.log(computerChoice);
computerChoice("paper");
}

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

console.log("Computer:" + computerChoice);
var compare=function(choice1, choice2)
{

if (choice1 === choice2){
return "The result is a tie!"
}
else if (choice1 === "rock"){
if(choice2 === "scissors"){
return "rock wins"
}
else{
return "paper wins"
}
}
else if (choice1 === "paper"){
if(choice2 === "rock"){
return "paper wins"
}
else{
return "scissors wins"
}
}
};
console.log(compare(userChoice, computerChoice));


#2

@kittydekat,
An else statement does NOT take a condition
you will have to remove the condition
from your

else (computerChoice) {

#3

thank you for helping.
but can you explain further?


#4

@kittydekat,
Please read
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else
== guidance ==
http://javascript.crockford.com/code.html <---JavaScript code-convention

Reference

google search
== the Book ==
javascript [your question] site:developer.mozilla.org
javascript if statement site:developer.mozilla.org
== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html <---JavaScript code-convention
http://javascript.crockford.com/survey.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide