I am working on a game and need to find a way to have the game run 3 times and print out the score for each round and declare a winner after three rounds. I have a good start but need some help. Here is the Java Script code: Please help.
$(document).ready(function(e){
var com, choice;
//this should only allow the process to run 3 times
//this will make the computer pick their weapon
function comPick() {
var pick = parseInt(Math.random()*6);
if ( pick == 1) {
com = “rock”;
}
else if ( pick == 2) {
com = “paper”;
}
else if ( pick == 3){
com = “scissors”;
}
else if ( pick == 4){
com = “lizzard”;
}
else if ( pick == 5){
com = “spock”;
}
}
//this will let the player pick their weapon
$(‘#rock’).click(function(e){
choice = “rock”;
comPick();
Winner();
return false;
});
$(‘#paper’).click(function(e){
choice = “paper”;
comPick();
Winner();
return false;
});
$(‘#scissors’).click(function(e){
choice = “scissors”;
comPick();
Winner();
return false;
});
$(‘#lizzard’).click(function(e){
choice = “lizzard”;
comPick();
Winner();
return false;
});
$(‘#spock’).click(function(e){
choice = “spock”;
comPick();
Winner();
return false;
});
//this will find the winner and print that out along with points added to total
function Winner(){
var line1, line2, winner, p1 = 0, p2 = 0;
if (choice == “rock” && com == “paper”){
winner = “You loose.”;
$(‘#line1’).html(“You picked rock”);
$(‘#line2’).html (“The computer picked paper, ” + winner);
p2 = p2 + 1;
}
else if (choice == “paper” && com == “scissors”){
winner = “You loose.”;
$(‘#line1’).html(“You picked paper.” );
$(‘#line2’).html(“The computer picked scissors, ” + winner);
p2 = p2 + 1;
}
else if (choice == “scissors” && com == “rock”){
winner = “You loose.”;
$(‘#line1’).html(“You picked scissors.” );
$(‘#line1’).html(” The computer picked rock, ” + winner);
p2 = p2 + 1;
}
else if (choice == “lizzard” && com == “rock”){
winner = “You loose.”;
$(‘#line1’).html(“You picked lizzard.”);
$(‘#line2’).html(“The computer picked rock, ” + winner);
p2 = p2 + 1;
}
else if (choice == “spock” && com == “lizzard”){
winner = “You loose.”;
$(‘#line1’).html(“You picked Spock.”);
$(‘#line2’).html(“The computer picked lizzard, ” + winner);
p2 = p2 + 1;
}
else if (choice == “scissors” && com == “spock”){
winner = “You loose.”;
$(‘#line1’).html(“You picked scissors.”);
$(‘#line2’).html(“The computer picked Spock, ” + winner);
p2 = p2 + 1;
}
else if (choice == “lizzard” && com == “scissors”){
winner = “You loose.”;
$(‘#line1’).html(“You picked lizzard.”);
$(‘#line2’).html(“The computer picked scissors, ” + winner);
p2 = p2 + 1;
}
else if (choice == “paper” && com == “lizzard”){
winner = “You loose.”;
$(‘#line1’).html(“You picked paper.”);
$(‘#line2’).html(“The computer picked lizzard, ” + winner);
p2 = p2 + 1;
$(‘#p2’).val(p2);
}
else if (choice == “spock” && com == “paper”){
winner = “You loose.”;
$(‘#line1’).html(“You picked Spock.”);
$(‘#line2’).html(“The computer picked paper, ” + winner);
p2 = p2 + 1;
}
else if (choice == “rock” && com == “spock”){
winner = “You loose.”;
$(‘#line1’).html(“You picked rock.”);
$(‘#line2’).html(“The computer picked Spock, ” + winner);
p2 = p2 + 1;
}
else if (choice == “rock” && com == “scissors”){
winner = “You win.”;
$(‘#line1’).html(“You picked rock.”) ;
$(‘#line2’).html(“The computer picked scissors, ” + winner);
p1 = p1 + 1;
}
else if (choice == “paper” && com == “rock”){
winner =”You win.”;
$(‘#line1’).html(“You picked paper.” );
$(‘#line2’).html(“The computer picked rock, ” + winner);
p1 = p1 + 1;
}
else if (choice == “scissors” && com == “paper”){
winner = “You win.”;
$(‘#line1’).html (“You picked scissors.” );
$(‘#line2’).html(“The computer picked paper, ” + winner);
p1 = p1 + 1;
}
else if (choice == “rock” && com == “lizzard”){
winner= “You win.”;
$(‘#line1’).html(“You picked rock.”);
$(‘#line2’).html(“The computer picked lizzard, ” + winner);
p1 = p1 + 1;
}
else if (choice == “lizzard” && com == “spock”){
winner= “You win.”;
$(‘#line1’).html(“You picked lizzard.”);
$(‘#line2’).html(“The computer picked Spock, ” + winner);
p1 = p1 + 1;
}
else if (choice == “spock” && com == “scissors”){
winner= “You win.”;
$(‘#line1’).html(“You picked Spock.”);
$(‘#line2’).html(“The computer picked scissors, ” + winner);
p1 = p1 + 1;
}
else if (choice == “scissors” && com == “lizzard”){
winner= “You win.”;
$(‘#line1’).html(“You picked scissors.”);
$(‘#line2’).html(“The computer picked lizzard, ” + winner);
p1 = p1 + 1;
}
else if (choice == “lizzard” && com == “paper”){
winner= “You win.”;
$(‘#line1’).html(“You picked lizzard.”);
$(‘#line2’).html(“The computer picked paper, ” + winner);
p1 = p1 + 1;
}
else if (choice == “paper” && com == “spock”){
winner= “You win.”;
$(‘#line1’).html(“You picked paper.”);
$(‘#line2’).html(“The computer picked Spock, ” + winner);
p1 = p1 + 1;
}
else if (choice == “spock” && com == “rock”){
winner= “You win.”;
$(‘#line1’).html(“You picked Spock.”);
$(‘#line2’).html(“The computer picked rock, ” + winner);
p1 = p1 + 1;
}
else{
winner = “it’s a tie”;
$(‘#line1’).html(“You picked ” + choice + “.”);
$(‘#line2’).html(“The computer picked ” + com + “, ” + winner);
}
}
function update(){
$(‘#p1’).html(p1);
$(‘#p2’).html(p2);
setTimeOut(‘update()’,1000)
}
});