Computer choice: part 1 -----stuck for ages, very confusing


#1

var userChoice = prompt ("rock,paper or scissor");
var computerChoice = Math.random();
console.log(computerChoice);

if (computerChoice < 0.33) {
computerChoice = "rock";
}
else if (computerChoice <= 0.64) {
computerChoice = "paper";
}
else if (computerChoice <= 1) {
computerChoice = "scissor");
}

var compare = function (userChoice,computerChoice);
{
if (userChoice === computerChoice);
{ return "The result is a Tie";
}
else if (userChoice === "rock") {
if (computerChoice === "scissor")
return "rock wins";
}
else
{ return "paper wins";
}

else if (userChoice === "paper") {
if (computerChoice === "rock")
return "paper wins";
}
else
{ return "scissor wins";
}

else if (userChoice === "scissor") {
if (computerChoice === "rock")
return "scissor wins";
}
else
{ return "scissor wins";
}
}


#2

having too much code in the exercise, can cause problems.


#3

thats exactly, what i thought,

let me start again.

thanks


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.