-
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
0 parents
commit a3cb5be
Showing
6 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,59 @@ | ||
body { | ||
background-color: rgb(25,25,25); | ||
color: white; | ||
font-family: Arial, Helvetica, sans-serif | ||
} | ||
|
||
button { | ||
background-color: white; | ||
} | ||
|
||
.title-of-page { | ||
font-size: 44px; | ||
font-weight: bold; | ||
word-spacing: 10px; | ||
padding-left: 10px; | ||
} | ||
|
||
.icon-box { | ||
word-spacing: 20px; | ||
} | ||
|
||
.reset-button { | ||
padding: 8px 13px; | ||
font-size: 15px; | ||
border: none; | ||
} | ||
|
||
.move-icon { | ||
height: 50px; | ||
} | ||
|
||
.move-button { | ||
background: transparent; | ||
border: 2px solid white; | ||
border-style: dotted; | ||
padding: 30px; | ||
border-radius: 50%; | ||
margin: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
.result { | ||
font-size: 25px; | ||
font-weight: bold; | ||
} | ||
|
||
.result-icon { | ||
height: 90px; | ||
margin-bottom: 20px; | ||
margin-left: 30px; | ||
} | ||
|
||
.reset-button { | ||
margin-top: 20px; | ||
padding: 20px 30px; | ||
border-radius: 20px; | ||
cursor: pointer; | ||
} | ||
|
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,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Rock paper scissors</title> | ||
<link rel="stylesheet" href="index.css"> | ||
</head> | ||
<body> | ||
<center> | ||
<p class="title-of-page">Rock Paper Scissors</p> | ||
<p class="icon-box"> | ||
<button class="move-button" onclick = "finalResult('rock');"><img class="move-icon" src="img/rock-emoji.png" ></button> | ||
|
||
<button class="move-button" onclick = "finalResult('paper');"><img class="move-icon" src="img/paper-emoji.png"></button> | ||
|
||
<button class="move-button" onclick = "finalResult('scissors');"><img class="move-icon" src="img/scissors-emoji.png"></button> | ||
</p> | ||
<p class="displayresult result"></p> | ||
<p class="display-move"></p> | ||
<p class="score-display"></p> | ||
<button class="reset-button" onclick = "score.wins = 0;score.losses = 0;score.ties = 0;localStorage.removeItem('score');display();">Reset score</button> | ||
</center> | ||
</body> | ||
<script src="index.js"></script> | ||
</html> |
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,90 @@ | ||
let score = JSON.parse(localStorage.getItem('score')) || { | ||
wins : 0, | ||
losses : 0, | ||
ties : 0 | ||
}; | ||
|
||
if(!score) { //score === null | ||
score = { | ||
wins : 0, | ||
losses : 0, | ||
ties : 0 | ||
}; | ||
} | ||
|
||
function display() { | ||
document.querySelector('.score-display').innerHTML = `Win:${score.wins} losses:${score.losses} tie:${score.ties}`; | ||
} | ||
|
||
display(); | ||
|
||
function pikeComputerMove() { | ||
|
||
const randomNumber = Math.random(); | ||
let computerMove = ''; | ||
|
||
if(randomNumber >= 0 && randomNumber < 1 / 3){ | ||
computerMove = 'rock'; | ||
} else if (randomNumber >= 1 / 3 && randomNumber < 2 / 3) { | ||
computerMove = 'paper'; | ||
}else if (randomNumber >= 2 / 3 && randomNumber < 1){ | ||
computerMove = 'scissors'; | ||
} | ||
return computerMove; | ||
} | ||
|
||
function finalResult(playerMove) { | ||
const computerMove = pikeComputerMove(); | ||
let result = ''; | ||
|
||
if(playerMove === 'rock'){ | ||
|
||
if(computerMove === 'rock'){ | ||
result = 'Tie.'; | ||
} else if(computerMove === 'paper'){ | ||
result = 'You lose.'; | ||
} else if(computerMove === 'scissors'){ | ||
result = 'You win.'; | ||
} | ||
|
||
}else if(playerMove === 'paper') { | ||
|
||
if(computerMove === 'paper'){ | ||
result = 'Tie.'; | ||
} else if(computerMove === 'scissors'){ | ||
result = 'You lose.'; | ||
} else if(computerMove === 'rock'){ | ||
result = 'You win.'; | ||
} | ||
|
||
}else if(playerMove === 'scissors') { | ||
|
||
if(computerMove === 'scissors'){ | ||
result = 'Tie.'; | ||
} else if(computerMove === 'rock'){ | ||
result = 'You lose.'; | ||
} else if(computerMove === 'paper'){ | ||
result = 'You win.'; | ||
} | ||
|
||
} | ||
|
||
if (result === 'You win.') { | ||
score.wins +=1; | ||
}else if (result === 'You lose.') { | ||
score.losses +=1; | ||
}else { | ||
score.ties += 1; | ||
} | ||
|
||
document.querySelector('.display-move').innerHTML = `You | ||
<img class="result-icon" src="./img/${playerMove}-emoji.png"> | ||
<img class="result-icon" src="./img/${computerMove}-emoji.png"> | ||
Computer`; | ||
document.querySelector('.displayresult').innerHTML = `${result}`; | ||
|
||
localStorage.setItem('score',JSON.stringify(score)); | ||
|
||
display(); | ||
|
||
} |