I\'m kind of new to JavaScript. I just started learning it, and I decided to make a \'Rock, Paper, Scissors, Lizard, Spock\' game. Here is the code:
var use
I would do something like the following (please note that the syntax may be off slightly):
var compare = function (choice1, choice2)
{
switch (choice1.tolower())
{
case "rock"
RockPicked(choice2);
break;
case "scissors"
ScissorsPicked(choice2);
break;
....
....
case default
alert ("Selection was invalid")
break;
}
}
// if the user picked rock then we compare the computers choice and decide winner
var RockPicked = function(choice2)
{
if (choice2 === "scissors")
{
alert("Rock wins!");
}
else if (choice2 === "paper")
{
alert("Paper wins!");
}
else if (choice2 === "lizard")
{
alert("Rock wins!");
}
else
{
alert("Spock wins!");
}
}