From ad834b8df7bae1241a7fd33c4ee76671fea84a3b Mon Sep 17 00:00:00 2001
From: Thuan Bui <9248622+10h30@users.noreply.github.com>
Date: Fri, 21 Feb 2025 19:56:06 +0900
Subject: [PATCH] Initial commit. Simple solution
---
index.html | 11 ++++++
script.js | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+)
create mode 100644 index.html
create mode 100644 script.js
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..5267fdf
--- /dev/null
+++ b/index.html
@@ -0,0 +1,11 @@
+
+
+
+
+
+ Document
+
+
+ >
+
+
\ No newline at end of file
diff --git a/script.js b/script.js
new file mode 100644
index 0000000..50f7cd1
--- /dev/null
+++ b/script.js
@@ -0,0 +1,103 @@
+function getComputerChoice() {
+ let a = 100 * Math.random();
+ let random = "";
+ if (a <= 33) {
+ random = "rock";
+ }
+ else if (a <=66 ){
+ random = "paper"
+ }
+ else {
+ random = "scissor"
+ }
+ return random;
+}
+
+function getHumanChoice() {
+ let input = prompt("Input please");
+ return input;
+}
+
+let humanScore = 0;
+let computerScore = 0;
+
+function playRound() {
+ const humanChoice = getHumanChoice();
+ const computerChoice = getComputerChoice();
+ console.log(humanChoice.toUpperCase());
+ console.log(computerChoice.toUpperCase());
+ switch (humanChoice.toUpperCase()) {
+ case "ROCK" :
+ switch (computerChoice.toUpperCase()) {
+ case "ROCK" :
+ console.log("Draw");
+ break;
+ case "PAPER" :
+ console.log("You lose! Paper beats Rock");
+ computerScore++;
+ break;
+ case "SCISSOR" :
+ console.log("You win! Rock beats Scissor");
+ humanScore++;
+ break;
+ }
+ break;
+
+ case "PAPER" :
+ switch (computerChoice.toUpperCase()) {
+ case "ROCK" :
+ console.log("You win! Paper beats Rock");
+ humanScore++;
+ break;
+ case "PAPER" :
+ console.log("Draw");
+ break;
+ case "SCISSOR" :
+ console.log("You lose! Scissor beats Paper");
+ computerScore++;
+ break;
+ }
+ break;
+
+ case "SCISSOR":
+ switch (computerChoice.toUpperCase()) {
+ case "ROCK" :
+ console.log("You lose! Rock beats Scissor");
+ computerScore++;
+ break;
+ case "PAPER" :
+ console.log("You win! Scissor beats Paper");
+ humanScore++;
+ break;
+ case "SCISSOR" :
+ console.log("Draw");
+ break;
+ }
+ break;
+ }
+
+}
+
+
+
+function playGames() {
+ //playRound(humanSelection, computerSelection);
+ playRound();
+ playRound();
+ playRound();
+ playRound();
+ playRound();
+ if (humanScore > computerScore) {
+ console.log("You Win!");
+ }
+ else if (humanScore == computerScore) {
+ console.log("Draw");
+ }
+ else {
+ console.log("You Lose");
+ }
+ console.log("The score is: " + humanScore + ":" + computerScore)
+}
+
+playGames();
+