diff --git a/rps_game/index.html b/rps_game/index.html new file mode 100644 index 0000000..f62e4b9 --- /dev/null +++ b/rps_game/index.html @@ -0,0 +1,23 @@ + + + + + + Rock Paper Scissors + + + + + +

Opponent Score

+

0

+ +
+ +
+
+

0

+

User Score

+ + + \ No newline at end of file diff --git a/rps_game/paper.png b/rps_game/paper.png new file mode 100644 index 0000000..9de18fb Binary files /dev/null and b/rps_game/paper.png differ diff --git a/rps_game/rock.png b/rps_game/rock.png new file mode 100644 index 0000000..cc52a2f Binary files /dev/null and b/rps_game/rock.png differ diff --git a/rps_game/scissors.png b/rps_game/scissors.png new file mode 100644 index 0000000..cf5489e Binary files /dev/null and b/rps_game/scissors.png differ diff --git a/rps_game/script.js b/rps_game/script.js new file mode 100644 index 0000000..50d2b21 --- /dev/null +++ b/rps_game/script.js @@ -0,0 +1,45 @@ +let you; +let yourScore = 0; +let opponent; +let opponentScore = 0; + +let choices = ["rock", "paper", "scissors"]; + +window.onload = function() { + for (let i = 0; i < 3; i++) { + let choice = document.createElement("img"); + choice.id = choices[i]; + choice.src = choices[i] + ".png"; + choice.addEventListener("click", selectChoice); + document.getElementById("choices").append(choice); + } +} + +function selectChoice() { + you = this.id; + document.getElementById("your-choice").src = you + ".png"; + + //random for oppponent + opponent = choices[Math.floor(Math.random() * 3)]; + document.getElementById("opponent-choice").src = opponent + ".png"; + + //check for winner + let user_win = ( (you === "rock") && (opponent === "scissors") || + (you === "paper") && (opponent === "rock") || + (you === "scissors") && (opponent === "paper")) + + + let computer_win = ( (opponent === "rock") && (you === "scissors") || + (opponent === "paper") && (you === "rock") || + (opponent === "scissors") && (you === "rock") ) + + user_win ? alert('yuppie😀 you got a point') : computer_win ? alert('shit😣 opponent got a point') : alert('Its a tie') + + scoreincrement(user_win,computer_win) + document.getElementById("your-score").innerText = yourScore; + document.getElementById("opponent-score").innerText = opponentScore; +} + +const scoreincrement = (user,computer_win)=>{ + return user ? yourScore += 1 : computer_win ? opponentScore +=1 : "" +} diff --git a/rps_game/style.css b/rps_game/style.css new file mode 100644 index 0000000..299e4d8 --- /dev/null +++ b/rps_game/style.css @@ -0,0 +1,27 @@ +body{ + font-family: Arial, Helvetica, sans-serif; + text-align: center; + background-color: blanchedalmond; +} +#opponent-choice{ + width: 240px; + height: 240px; + margin-top: 10px; + +} +#your-choice{ + width: 240px; + height: 240px; + margin-top: 10px; + +} +#choices{ + width: 240px; + height: 80px; + margin-top: 10px; + margin: 0 auto; +} +#choices img{ + width: 80px; + height: 80px; +}