-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aae3bf4
commit 0f23d35
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |