For the following code, I keep getting Scissors back for alert. I am not sure what am I doing wrong here.
var computerChoice = Math.random();
var newChoice = function (computerChoice) {
if (computerChoice <= 0.34) {
var newChoice = "rock";
return newChoice;
} else if ((computerChoice >= 0.35) && (computerChoice <= 0.66)) {
var newChoice = "paper";
return newChoice;
} else {
var newChoice = "scissors";
return newChoice;
}
}
var newerChoice = newChoice();
alert(newerChoice);
newChoicewhen you call it, hencecomputerChoice(the parameter of the function) isundefined.undefined <= 0.34isfalse, same for the other comparisons.