From b62219992ded37a936acd153b8af018f1d34f8e2 Mon Sep 17 00:00:00 2001 From: "Glitch (ro-pa-sci-proct)" Date: Fri, 10 Dec 2021 00:40:28 +0000 Subject: [PATCH 1/4] Results of game now show --- README.md | 20 ++++++++++---------- js/script.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f108acf1..ce984cf6 100644 --- a/README.md +++ b/README.md @@ -25,38 +25,38 @@ In this unit, coders will create a Rock, Paper, Scissors game. The Rock, Paper, ### Day 1 Goal 2: Capture user input and display it to the screen -- [ ] Add a click handler that saves the value of the user's input to a variable -- [ ] Display the user input value on the screen, in the user choice location +- [x] Add a click handler that saves the value of the user's input to a variable +- [x] Display the user input value on the screen, in the user choice location #### Wrap -- [ ] Commit your changes! +- [x] Commit your changes! ## Day 2 ### Day 2 Goal 1: Generate a new random number every time the user clicks the button -- [ ] Outside of your click handler, declare a randomNumber variable and set it equal to 0 -- [ ] In your click handler, generate a random number and assign it to the randomNumber variable +- [x] Outside of your click handler, declare a randomNumber variable and set it equal to 0 +- [x] In your click handler, generate a random number and assign it to the randomNumber variable ### Day 2 Goal 2: Display the random number to the screen -- [ ] Display the randomNumber value on the screen, in the computer choice location +- [x] Display the randomNumber value on the screen, in the computer choice location #### Wrap -- [ ] Commit your changes! +- [X] Commit your changes! ## Day 3 ### Day 3 Goal 1: Assign different computer choices depending on the random number -- [ ] Write a conditional statement which, given the number range of randomNumber, assigns ‘rock’, ‘paper’ or ‘scissors’ to a computerChoice variable -- [ ] Update the computer choice location so it displays the computerChoice to the screen +- [x] Write a conditional statement which, given the number range of randomNumber, assigns ‘rock’, ‘paper’ or ‘scissors’ to a computerChoice variable +- [x] Update the computer choice location so it displays the computerChoice to the screen ### Day 3 Goal 2: Increase user experience (BONUS!) -- [ ] Test for edge cases by ensuring that a result appears if the user does not type an acceptable input +- [x] Test for edge cases by ensuring that a result appears if the user does not type an acceptable input ## Day 4 diff --git a/js/script.js b/js/script.js index 8b137891..ff0307ce 100644 --- a/js/script.js +++ b/js/script.js @@ -1 +1,44 @@ - +let randomNumber; +let computerChoice; +$(".play").click(function() { + let choice = $(".input").val(); + if (choice === "rock" || choice === "paper" || choice === "scissors") { + $(".userChoice").text(choice); + } else { + $(".userChoice").text("Invalid Input"); + } + randomNumber = Math.random() * 3; + //$(".computerChoice").append(randomNumber); + if (randomNumber < 1) { + computerChoice = "rock"; + } else if (randomNumber < 2) { + computerChoice = "paper"; + } else { + computerChoice = "scissors"; + } + $(".computerChoice").text(computerChoice); + //draw + if (choice === computerChoice) { + $(".result").text("Draw"); + } + //lose + if (choice === "rock" && computerChoice === "paper") { + $(".result").text("YOU LOSE!"); + } + if (choice === "paper" && computerChoice === "scissors") { + $(".result").text("YOU LOSE!"); + } + if (choice === "scissors" && computerChoice === "rock") { + $(".result").text("YOU LOSE!"); + } + //win + if (choice === "rock" && computerChoice === "scissors") { + $(".result").text("YOU WIN!"); + } + if (choice === "paper" && computerChoice === "rock") { + $(".result").text("YOU WIN!"); + } + if (choice === "scissors" && computerChoice === "paper") { + $(".result").text("YOU WIN!"); + } +}); From e7d24ad80e4332cd899a9779a35ed682d21727c6 Mon Sep 17 00:00:00 2001 From: "Glitch (ro-pa-sci-proct)" Date: Wed, 12 Jan 2022 00:29:16 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8D=8A=F0=9F=8E=A5=20Updated=20with?= =?UTF-8?q?=20Glitch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 ++++++++++++++++---------------- js/script.js | 48 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ce984cf6..93857b29 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ In this unit, coders will create a Rock, Paper, Scissors game. The Rock, Paper, #### Planning -- [ ] Complete the project planning document +- [X] Complete the project planning document #### GitHub Set-Up - [x] Go to the repository at https://github.com/itscodenation/rockpaperscissors -- [ ] Fork this repository to your Github account and import to a new workspace -- [ ] Link and commit your changes -- [ ] Make your site live on GitHub Pages +- [?] Fork this repository to your Github account and import to a new workspace +- [?] Link and commit your changes +- [X] Make your site live on GitHub Pages #### Code Walkthrough @@ -62,35 +62,35 @@ In this unit, coders will create a Rock, Paper, Scissors game. The Rock, Paper, ### Day 4 Goal 1: Compare the user choice and computer choice to determine a winner -- [ ] Write a compound conditional statement that compares the userChoice to the computerChoice -- [ ] Declare a variable to save the winner of the game -- [ ] Display the winner to the screen in the result div +- [x] Write a compound conditional statement that compares the userChoice to the computerChoice +- [x] Declare a variable to save the winner of the game +- [?] Display the winner to the screen in the result div ### Day 4 Goal 2: Increase user experience (BONUS!) -- [ ] Test that your game performs correctly in case of a tie -- [ ] Clear the input value once a result is displayed so your game is ready to play again +- [x] Test that your game performs correctly in case of a tie +- [?] Clear the input value once a result is displayed so your game is ready to play again #### Wrap -- [ ] Commit your changes! +- [X] Commit your changes! #### Day 5 ### Day 5 Goal 1: Create a function to handle your computer choice logic -- [ ] Write a function called getRandomComputerChoice that does not accept any parameters and returns computerChoice -- [ ] Move your `Math.random` inside your function -- [ ] Move your conditional logic that determines the computer choice inside your function +- [x] Write a function called getRandomComputerChoice that does not accept any parameters and returns computerChoice +- [x] Move your `Math.random` inside your function +- [x] Move your conditional logic that determines the computer choice inside your function ### Day 5 Goal 2: Call your getRandomComputerChoice function -- [ ] Call your function inside your click handler so that it determines the value of your computerChoice variable - - [ ] HINT: Your getRandomComputerChoice function works correctly if it returns rock, paper, or scissors when called +- [x] Call your function inside your click handler so that it determines the value of your computerChoice variable + - [x] HINT: Your getRandomComputerChoice function works correctly if it returns rock, paper, or scissors when called #### Wrap -- [ ] Commit your changes! +- [x] Commit your changes! #### Day 6 diff --git a/js/script.js b/js/script.js index ff0307ce..dde7c964 100644 --- a/js/script.js +++ b/js/script.js @@ -1,14 +1,19 @@ +//Global Variables let randomNumber; let computerChoice; -$(".play").click(function() { - let choice = $(".input").val(); - if (choice === "rock" || choice === "paper" || choice === "scissors") { - $(".userChoice").text(choice); - } else { - $(".userChoice").text("Invalid Input"); - } + +$(".play").click(function () { + + //Generate computer's choice + computerChoice = getRandomComputerChoice(); + $(".computerChoice").text(computerChoice); + + $(".result").append(winner); + +}); + +function getRandomComputerChoice() { randomNumber = Math.random() * 3; - //$(".computerChoice").append(randomNumber); if (randomNumber < 1) { computerChoice = "rock"; } else if (randomNumber < 2) { @@ -16,29 +21,52 @@ $(".play").click(function() { } else { computerChoice = "scissors"; } - $(".computerChoice").text(computerChoice); + + return computerChoice; +} + +function chooseWinner(winner, choice) { + + choice = $(".input").val(); + if (choice === "rock" || choice === "paper" || choice === "scissors") { + $(".userChoice").text(choice); + } else { + $(".userChoice").text("Invalid Input"); + } + //draw if (choice === computerChoice) { + winner = ""; $(".result").text("Draw"); } + //lose if (choice === "rock" && computerChoice === "paper") { + winner = " Computer"; $(".result").text("YOU LOSE!"); } if (choice === "paper" && computerChoice === "scissors") { + winner = " Computer"; $(".result").text("YOU LOSE!"); } if (choice === "scissors" && computerChoice === "rock") { + winner = " Computer"; $(".result").text("YOU LOSE!"); } + //win if (choice === "rock" && computerChoice === "scissors") { + winner = " User"; $(".result").text("YOU WIN!"); } if (choice === "paper" && computerChoice === "rock") { + winner = " User"; $(".result").text("YOU WIN!"); } if (choice === "scissors" && computerChoice === "paper") { + winner = " User"; $(".result").text("YOU WIN!"); } -}); + + return winner; +} From 1e681f7e26d99a47d8e5bb79ad3bab5777d4331e Mon Sep 17 00:00:00 2001 From: "Glitch (ro-pa-sci-proct)" Date: Thu, 13 Jan 2022 23:14:22 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A4=91=E2=8C=9B=20Updated=20with=20Gl?= =?UTF-8?q?itch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 +++++++++--------- js/script.js | 26 +++++++++++++++++--------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 93857b29..042d0827 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ In this unit, coders will create a Rock, Paper, Scissors game. The Rock, Paper, #### Code Walkthrough -- [ ] Read through the starter code given so you understand how the HTML is organized +- [x] Read through the starter code given so you understand how the HTML is organized ### Day 1 Goal 2: Capture user input and display it to the screen @@ -64,12 +64,12 @@ In this unit, coders will create a Rock, Paper, Scissors game. The Rock, Paper, - [x] Write a compound conditional statement that compares the userChoice to the computerChoice - [x] Declare a variable to save the winner of the game -- [?] Display the winner to the screen in the result div +- [x] Display the winner to the screen in the result div ### Day 4 Goal 2: Increase user experience (BONUS!) - [x] Test that your game performs correctly in case of a tie -- [?] Clear the input value once a result is displayed so your game is ready to play again +- [x] Clear the input value once a result is displayed so your game is ready to play again #### Wrap @@ -96,23 +96,23 @@ In this unit, coders will create a Rock, Paper, Scissors game. The Rock, Paper, ### Day 6 Goal 1: Create a function to handle your winner logic -- [ ] Write a function called chooseWinner that does accepts two parameters and returns winner -- [ ] Move your compound conditional logic that determines the winner inside your function +- [x] Write a function called chooseWinner that does accepts two parameters and returns winner +- [x] Move your compound conditional logic that determines the winner inside your function ### Day 6 Goal 2: Call your chooseWinner function -- [ ] Call your function inside your click handler so that it determines the value of your winner variable +- [x] Call your function inside your click handler so that it determines the value of your winner variable - [ ] HINT: Your chooseWinner function works correctly if it returns "User wins!", "Computer wins!" or "No one wins!" when called #### Wrap -- [ ] Commit your changes! +- [x] Commit your changes! ## Projects Extensions: - [ ] Style the page to fit your personality -- [ ] Validates input so that it will return “Not valid input” if the user types in a wrong choice. -- [ ] Accepts any form of a word regardless of capitalization (i.e. “Rock” “rock” roCk”) +- [x] Validates input so that it will return “Not valid input” if the user types in a wrong choice. +- [x] Accepts any form of a word regardless of capitalization (i.e. “Rock” “rock” roCk”) - [ ] Keeps track of total wins and losses, until the page refreshes. - [ ] Create a game with more variety in throwing options. Example: [Rock-Paper-Scissors-Lizard-Spock](http://en.wikipedia.org/wiki/Rock-paper-scissors-lizard-Spock) diff --git a/js/script.js b/js/script.js index dde7c964..79620e2e 100644 --- a/js/script.js +++ b/js/script.js @@ -3,12 +3,23 @@ let randomNumber; let computerChoice; $(".play").click(function () { - + + //User choice + let choice = $(".input").val(); + choice = choice.toLowerCase(); + if (choice === "rock" || choice === "paper" || choice === "scissors") { + $(".userChoice").text(choice); + } else { + $(".userChoice").text("Invalid Input"); + } + //Generate computer's choice computerChoice = getRandomComputerChoice(); $(".computerChoice").text(computerChoice); - $(".result").append(winner); + chooseWinner(choice, computerChoice) + + $(".input").val(""); }); @@ -25,14 +36,9 @@ function getRandomComputerChoice() { return computerChoice; } -function chooseWinner(winner, choice) { +function chooseWinner(choice, computerChoice) { - choice = $(".input").val(); - if (choice === "rock" || choice === "paper" || choice === "scissors") { - $(".userChoice").text(choice); - } else { - $(".userChoice").text("Invalid Input"); - } + let winner; //draw if (choice === computerChoice) { @@ -70,3 +76,5 @@ function chooseWinner(winner, choice) { return winner; } + + From 20b83da7f9e0ca009b176a4b3c6ec1fa7daefb87 Mon Sep 17 00:00:00 2001 From: "Glitch (ro-pa-sci-proct)" Date: Thu, 13 Jan 2022 23:28:17 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=92=A2=F0=9F=91=91=20Updated=20with?= =?UTF-8?q?=20Glitch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/script.js b/js/script.js index 79620e2e..c79e2cdc 100644 --- a/js/script.js +++ b/js/script.js @@ -12,7 +12,7 @@ $(".play").click(function () { } else { $(".userChoice").text("Invalid Input"); } - + //Generate computer's choice computerChoice = getRandomComputerChoice(); $(".computerChoice").text(computerChoice);