Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
.DS_Store
.vscode
*.code-workspace
33 changes: 29 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const options = ["rock", "paper", "scissor"];
let score = {
you: 0,
computer: 0
computer: 0,
};
const WIN_GREEN = "#6ac475";
const LOSE_RED = "#c4736a";
Expand All @@ -16,10 +16,37 @@ btns.forEach((btn) => {
btn.addEventListener("click", () => {
const playerA = btn.querySelector("label").innerText;
const playerB = options[getRandomInt()];
compare(playerA, playerB);
countdown().then(() => {
compare(playerA, playerB);
});
});
});

async function countdown() {
return new Promise((resolve) => {
const countdownSayings = [...options, "shoot!"].map((x) => x.toUpperCase());
let counter = 0;
const countdownLabel = document.querySelector(".result");
countdownLabel.innerText = "";
countdownLabel.style.color = "#fff";
const inst = setInterval(changeText, 500);

function changeText() {
countdownLabel.innerText = countdownSayings[counter];
counter++;

if (counter >= countdownSayings.length) {
counter = 0;
clearInterval(inst);
setTimeout(() => {
countdownLabel.innerText = "";
resolve();
}, 500);
}
}
});
}

function compare(player, computer) {
const won = "YOU WON";
const lose = "YOU LOST";
Expand Down Expand Up @@ -103,7 +130,6 @@ function update(player, computer) {
}
}


//Reset Game Button ---------------------------------
const resetBtn = document.querySelector(".reset");
resetBtn.addEventListener("click", () => {
Expand All @@ -116,7 +142,6 @@ resetBtn.addEventListener("click", () => {
document.querySelector(".hands .computer-hand").src = "rock.png";
});


// // Mapping
// // 0 -> rock, 1->paper, 2->scissor
// const options = ["rock", "paper", "scissor"];
Expand Down
123 changes: 64 additions & 59 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,70 +1,75 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap" rel="stylesheet">
<title>Rock,paper & scissor</title>

<link rel="stylesheet" href="style.css" />
<script src="app.js" defer></script>
</head>
<body>
<section class="game">
<div class="intro">
<h1>Rock, Paper & Scissors</h1>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap"
rel="stylesheet">
<title>Rock,paper & scissor</title>

<link rel="stylesheet" href="style.css" />
<script src="app.js" defer></script>
</head>

<body>
<section class="game">
<div class="intro">
<h1>Rock, Paper & Scissors</h1>
</div>

<div class="score">
<h2>
You
<br>
<hr>
Score: <span class="you">0</span>
</h2>
<h2>
Computer
<br>
<hr>
Score: <span class="computer">0</span>
</h2>
</div>

<div class="match">
<div class="hands">
<img class="player-hand" src="rock.png" alt="" />
<h2 class="result"></h2>
<img class="computer-hand" src="rock.png" alt="" />
</div>

<div class="score">
<h2>
You
<h2 class="winner">Choose an option</h2>
<div class="options">
<button class="rock">
<img src="./rock.svg" alt="rock"></img>
<br>
<hr>
Score: <span class="you">0</span>
</h2>
<h2>
Computer
<label>rock</label>
</button>
<button class="paper">
<img src="./paper.svg" alt="paper"></img>
<br>
<hr>
Score: <span class="computer">0</span>
</h2>
<label>paper</label>
</button>
<button class="scissor">
<img src="./scissor.svg" alt="scissor"></img>
<br>
<label>scissor</label>
</button>
</div>
</div>

<div class="match">
<div class="hands">
<img class="player-hand" src="rock.png" alt="" />
<h2 class="result"></h2>
<img class="computer-hand" src="rock.png" alt="" />
</div>
<!----- Reset Button ----->
<div class="reset-div">
<button class="reset">Reset Game</button>
</div>

<h2 class="winner">Choose an option</h2>
<div class="options">
<button class="rock">
<img src="./rock.svg" alt="rock"></img>
<br>
<label>rock</label>
</button>
<button class="paper">
<img src="./paper.svg" alt="paper"></img>
<br>
<label>paper</label>
</button>
<button class="scissor">
<img src="./scissor.svg" alt="scissor"></img>
<br>
<label>scissor</label>
</button>
</div>
</div>

<!----- Reset Button ----->
<div class="reset-div">
<button class="reset">Reset Game</button>
</div>
</section>
</body>

</section>
</body>
</html>
</html>
65 changes: 34 additions & 31 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ section {
width: 80vw;
}


/*--- Reset Button -----*/
.reset{
.reset {
background: #0f0f0f;
border: 1px solid #fff;
color: #fff;
Expand All @@ -29,12 +28,12 @@ section {
transition: all 0.3s ease;
}

.reset:hover{
.reset:hover {
background: #fff;
color: #0f0f0f;
}

.reset-div{
.reset-div {
text-align: center;
}
/*--------------------*/
Expand All @@ -55,21 +54,20 @@ section {
text-align: center;
}

.score h2{
.score h2 {
font-weight: 400;
}

.score hr{
.score hr {
margin-top: 25px;
margin-bottom: 25px;
}

.winner{
.winner {
font-weight: 400;
}

@media screen and (max-width:725px) {

@media screen and (max-width: 725px) {
}
.match {
display: flex;
Expand Down Expand Up @@ -118,66 +116,71 @@ section {
background-color: transparent;
}

.options button label{
.options button label {
font-size: 18px;
margin-top: 0px;
opacity: 0;
display: none;
}

.options button:hover > label{
.options button:hover > label {
margin-top: 25px;
display: inline-block;
opacity: 1;
}

.options button img{
.options button img {
height: 50px;
}

.options .paper img{
.options .paper img {
width: 50px;
height: auto;
}

.options .rock img{
.options .rock img {
margin-top: 10px;
}

.options .scissor img{
.options .scissor img {
margin-top: 10px;
}

h2.result {
width: 300px;
}

@media screen and (max-width: 810px) {
.score{
.score {
max-width: 60vw;
}
.player-hand, .computer-hand {
.player-hand,
.computer-hand {
width: 215px;
}
h2.result{
h2.result {
font-size: 1.3rem;
}
h2.winner{
h2.winner {
font-size: 1.5rem;
}
}

@media screen and (max-width: 550px) {
.score{
.score {
max-width: 70vw;
}
.hands{
.hands {
gap: 1rem;
}
.player-hand,
.computer-hand{
width: 170px;
}
h2.result{
font-size: 1.2rem;
}
h2.winner{
font-size: 1.5rem;
}
.player-hand,
.computer-hand {
width: 170px;
}
h2.result {
font-size: 1.2rem;
}
h2.winner {
font-size: 1.5rem;
}
}