Skip to content

Commit 65f46b3

Browse files
committed
done
1 parent 125c126 commit 65f46b3

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Project: Rock Paper Scissors</title>
8+
</head>
9+
10+
<body>
11+
<script src="script.js"></script>
12+
</body>
13+
14+
</html>

script.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// console.log("hello");
2+
3+
let humanScore = 0;
4+
let computerScore = 0;
5+
6+
function getComputerChoice() {
7+
let randomNumber = Math.floor(Math.random() * 3); //randomly generates a number between 0, 1, 2
8+
9+
if (randomNumber === 0) {
10+
return "Rock";
11+
} else if (randomNumber === 1) {
12+
return "Paper";
13+
} else {
14+
return "Scissors";
15+
}
16+
}
17+
18+
function getHumanChoice() {
19+
let choice = prompt("Choose between rock/paper/scissors.");
20+
if (choice === "rock") {
21+
return "Rock";
22+
} else if (choice === "paper") {
23+
return "Paper";
24+
} else if (choice === "scissors") {
25+
return "Scissors";
26+
} else {
27+
return "Invalid option, choose between rock/paper/scissors.";
28+
}
29+
}
30+
31+
function playRound(humanChoice, computerChoice) {
32+
console.log(humanChoice, computerChoice);
33+
if (humanChoice === "Rock" && computerChoice === "Scissors") {
34+
humanScore++;
35+
console.log(`Final Score - Human: ${humanScore}, Computer: ${computerScore}`);
36+
return "You win! Rock beats Scissors.";
37+
} else if (humanChoice === "Paper" && computerChoice === "Rock") {
38+
humanScore++;
39+
console.log(`Final Score - Human: ${humanScore}, Computer: ${computerScore}`);
40+
return "You win! Paper beats Rock.";
41+
} else if (humanChoice === "Scissors" && computerChoice === "Paper") {
42+
humanScore++;
43+
return "You Win! Scissors beats Paper.";
44+
} else if (humanChoice === computerChoice) {
45+
console.log(`Final Score - Human: ${humanScore}, Computer: ${computerScore}`);
46+
return "It's a tie.";
47+
} else {
48+
computerScore++;
49+
console.log(`Final Score - Human: ${humanScore}, Computer: ${computerScore}`);
50+
}
51+
}
52+
53+
// const humanSelection = getHumanChoice();
54+
// const computerSelection = getComputerChoice();
55+
56+
// console.log(playRound(humanSelection, computerSelection));
57+
58+
function playGame() {
59+
let rounds = 0;
60+
61+
while (rounds < 5) {
62+
let newHumanChoice = getHumanChoice();
63+
let newComputerChoice = getComputerChoice();
64+
playRound(newHumanChoice, newComputerChoice);
65+
rounds++;
66+
}
67+
if (humanScore > computerScore) {
68+
return "You Win!";
69+
} else if (humanScore < computerScore) {
70+
return "You Lose!";
71+
} else {
72+
return "It's a draw.";
73+
}
74+
}
75+
76+
console.log(playGame());
77+

0 commit comments

Comments
 (0)