Skip to content

Commit f8d3916

Browse files
authored
PR #26: Rock-Paper-Scissor (Added Reset Score Feature)
Reset score feature Merge pull request #26 from HeemahMuslad/Reset-Score-Feature
2 parents 92fc827 + 0ae375e commit f8d3916

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

Rock-Paper-Scissors-Game/app.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const computerChoiceDisplay = document.getElementById("computer-choice");
22
const userChoiceDisplay = document.getElementById("user-choice");
33
const resultDisplay = document.getElementById("winner");
44
const possibleChoices = document.querySelectorAll(".button-container > img");
5+
const resetScoreElement = document.querySelector(".js-resetScore-button");
6+
resetScoreElement.addEventListener("click", () => {
7+
resetScore();
8+
});
59

610
let userChoice;
711
let computerChoice;
@@ -60,3 +64,17 @@ function scoreElement() {
6064
".js-score"
6165
).innerHTML = `Wins: ${score.wins}, Losses: ${score.losses}, Ties: ${score.ties}.`;
6266
}
67+
function resetScore() {
68+
const message = document.querySelector(".js-confirmation-message");
69+
message.innerHTML =
70+
"Are you sure you want to reset the score? <button class='js-yes-button message-button'>Yes</button> <button class='js-no-button message-button'>No</button>";
71+
document.querySelector(".js-yes-button").addEventListener("click", () => {
72+
(score.wins = 0), (score.losses = 0), (score.ties = 0);
73+
localStorage.removeItem("score");
74+
scoreElement();
75+
message.innerHTML = "";
76+
});
77+
document.querySelector(".js-no-button").addEventListener("click", () => {
78+
message.innerHTML = "";
79+
});
80+
}

Rock-Paper-Scissors-Game/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ <h2>
3030
<img id="Scissors" src="./public/scissors.png" alt="Scissors" />
3131
</div>
3232
<p class="js-score score"></p>
33+
<button class="js-resetScore-button resetScore">Reset Score</button>
34+
<p class="js-confirmation-message message-button"></p>
3335

3436
<div class="winner-container">
3537
<h2>Winner:</h2>

Rock-Paper-Scissors-Game/style.css

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
body {
2-
background-color: #eec6c6;
3-
font-family: 'Arial', sans-serif;
2+
background-color: #eec6c6;
3+
font-family: "Arial", sans-serif;
44
text-align: center;
5-
background-image: linear-gradient(to bottom, #f9b4c2, #ffdb86);
5+
background-image: linear-gradient(to bottom, #f9b4c2, #ffdb86);
66
color: #ffffff;
77
position: relative;
88
min-height: 91.5vh;
@@ -13,25 +13,29 @@ body {
1313
}
1414

1515
body::before {
16-
content: '';
16+
content: "";
1717
position: fixed;
1818
top: 0;
1919
left: 0;
2020
width: 100%;
2121
height: 100%;
22-
background-image: radial-gradient(ellipse at center, rgba(246, 231, 231, 0.813) 0%, rgba(0,0,0,0.9) 100%);
22+
background-image: radial-gradient(
23+
ellipse at center,
24+
rgba(246, 231, 231, 0.813) 0%,
25+
rgba(0, 0, 0, 0.9) 100%
26+
);
2327
z-index: -1;
2428
}
2529

26-
2730
h1 {
2831
font-size: 36px;
2932
font-weight: bold;
3033
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
3134
margin-bottom: 20px;
3235
}
3336

34-
h2 {
37+
h2,
38+
.score {
3539
color: #ffffff;
3640
font-size: 24px;
3741
font-weight: bold;
@@ -55,7 +59,10 @@ button {
5559
cursor: pointer;
5660
transition: background-color 0.3s ease;
5761
}
58-
62+
.resetScore {
63+
width: 15%;
64+
margin: 0 auto;
65+
}
5966
button:hover {
6067
background-color: #45a049;
6168
}
@@ -74,7 +81,6 @@ button:hover {
7481
display: flex;
7582
justify-content: center;
7683
margin-bottom: 20px;
77-
7884
}
7985

8086
.button-container > button {
@@ -144,15 +150,13 @@ nav {
144150
font-size: 18px;
145151
}
146152

147-
148-
.button-container>img{
153+
.button-container > img {
149154
width: 10%;
150155
margin: 0 10px;
151156
cursor: pointer;
152-
153157
}
154158

155-
.logo{
159+
.logo {
156160
width: 20%;
157161
}
158162

@@ -166,10 +170,12 @@ footer {
166170
width: 98.7%;
167171
}
168172

169-
#Rock , #Paper, #Scissors{
173+
#Rock,
174+
#Paper,
175+
#Scissors {
170176
margin: 5%;
171-
}
177+
}
172178

173-
#winner{
179+
#winner {
174180
width: 5px;
175-
}
181+
}

0 commit comments

Comments
 (0)