Skip to content

Commit

Permalink
the project have been complete
Browse files Browse the repository at this point in the history
  • Loading branch information
shahidafridi-321 committed Mar 21, 2024
1 parent aae3bf4 commit 0f23d35
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# rock-paper-scissor
# rock-paper-scissor
lets do the project
it's a game between two players so one can win...
86 changes: 86 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock Paper Scissor Game</title>
</head>
<body>
<script>
let player_wins_counter = 0;
let computer_wins_counter = 0;
playGame();

function playGame()
{
for (let i = 0; i<5;i++)
{

let playerSelection = prompt("Rock,Paper,Scissor ").toLowerCase();
let choices = ["rock","paper","scissor"];

let computerSelection = getComputedChoice(choices);
console.log(playRound(playerSelection,computerSelection));

function playRound(player_one,player_two)
{

if (player_one===player_two)
{
let messege = "The Round is Tie!";
let result = messege + " the score is " + player_wins_counter +":"+computer_wins_counter;
return result;
}
else if ((player_one === "rock" && player_two === "scissor") || (player_one === "scissor" && player_two === "paper") || (player_one === "paper" && player_two === "rock") )
{
let messege = "the player wins the round";
player_wins_counter++;
let result = messege + " the score is " + player_wins_counter +":"+computer_wins_counter;
return result;
}
else if ((player_two === "rock" && player_one === "scissor") || (player_two === "scissor" && player_one === "paper") || (player_two === "paper" && player_one === "rock") )
{
let messege = "the Computer wins the round";
computer_wins_counter++;
let result = messege + " the score is " + player_wins_counter +":"+computer_wins_counter;
return result;
}
else
{
let messege = "incorrect choice";
i--;
return messege;
}

}



function getComputedChoice(ch)
{
let index_of_choice = Math.floor(Math.random()*3);
let choisen = ch[index_of_choice];
return choisen;
}

}
}
if(player_wins_counter > computer_wins_counter)
{
console.log("You Have Won the Game Congratulations! with the Score "+ player_wins_counter +":"+computer_wins_counter);
}
else if (player_wins_counter < computer_wins_counter)
{
console.log("Computer Have Won the Game , Try Again... Scores are "+ player_wins_counter +":"+computer_wins_counter);

}
else
{
console.log("the Game is tied , with the Scores "+ player_wins_counter +":"+computer_wins_counter);

}


</script>
</body>
</html>

0 comments on commit 0f23d35

Please sign in to comment.