-
Notifications
You must be signed in to change notification settings - Fork 0
Rock Paper Scissors #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,109 @@ const rl = readline.createInterface({ | |
| }); | ||
|
|
||
|
|
||
| const user1 = 'player1'; | ||
| const user2 = 'player2'; | ||
|
|
||
|
|
||
| function rockPaperScissors(hand1, hand2) { | ||
|
|
||
| // Write code here | ||
|
|
||
| } | ||
|
|
||
| // 1. User1 input of rock, paper, or scissors. | ||
| const choice = ['rock', 'paper' , 'scissors']=>{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invalid syntax |
||
| if (! choice) { | ||
| // User choice was undefined | ||
| return ("<p>Player 1, type in a correct input (rock, paper, or scissors).</p>"); | ||
| } else { | ||
| // Display user choice | ||
| return("<p>Player 1:" + " " + choice + "</p>") | ||
| } | ||
| }; | ||
|
|
||
| // 2. User2 input of rock, paper, or scissors. | ||
| const choice = ['rock', 'paper' , 'scissors']=>{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invalid syntex |
||
| if (! choice) { | ||
| // User choice was undefined | ||
| return ("<p>Player 2, type in a correct input (rock, paper, or scissors).</p>"); | ||
| } else { | ||
| // Display user choice | ||
| return("<p>Player 2:" + " " + choice + "</p>") | ||
| } | ||
| }; | ||
|
|
||
| // 3. Compare User1 input to User2 input. | ||
| const checkUserInput=()=>{ | ||
|
|
||
| }; | ||
|
|
||
| // 4. If User1 input is 'rock' and User2 input is 'scissor', User1 wins. | ||
| if (user1 === "rock") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if statement not closed |
||
| if (user2 === "scissors") { | ||
| // rock wins | ||
| return "You win!"; | ||
| } else { | ||
| // paper wins | ||
| return "You lose! Try again."; | ||
| } | ||
| }; | ||
|
|
||
| // 5. If User1 input is 'rock' and User2 input is 'paper', User2 wins. | ||
| if (user1 === "rock") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if statement not closed |
||
| if (user2 === "paper") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if statement not closed |
||
| // paper wins | ||
| return "You win!"; | ||
| }; | ||
|
|
||
| // 6. If User1 input is 'rock' and User2 input is 'rock', it's a tie. | ||
| const compare = (hand1,hand2)=> { | ||
| if (hand1 === hand2) { | ||
| return "It's a tie!"; | ||
| } | ||
|
|
||
| // 7. If User1 input is 'paper' and User2 input is 'rock', User1 wins. | ||
| if (user1 === "paper") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if statement not closed |
||
| if (user2 === "rock") { | ||
| // paper wins | ||
| return "You win!"; | ||
| } | ||
|
|
||
| // 8. If User1 input is 'paper' and User2 input is 'scissors', User2 wins. | ||
| if (user1 === "rock") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if statement not closed |
||
| if (user2 === "scissors") { | ||
| // scissors wins | ||
| return "You win!"; | ||
| } | ||
|
|
||
| // 9. If User1 input is 'paper' and User2 input is 'paper', it's a tie. | ||
| const compare = (hand1,hand2)=> { | ||
| if (hand1 === hand2) { | ||
| return "It's a tie!"; | ||
| } | ||
|
|
||
| // 10. If User1 input is 'scissors' and User2 input is 'paper', User1 wins. | ||
| if (user1 === "scissors") { | ||
| if (user2 === "paper") { | ||
| // scissors wins | ||
| return "You win!"; | ||
| } | ||
|
|
||
| // 11. If User1 input is 'scissors' and User2 input is 'rock', User2 wins. | ||
| if (user1 === "scissors") { | ||
| if (user2 === "rock") { | ||
| // rock wins | ||
| return "You win!"; | ||
| } | ||
|
|
||
| // 12. If User1 input is 'scissors' and User2 input is 'scissors', it's a tie. | ||
| const compare = (hand1,hand2)=> { | ||
| if (hand1 === hand2) { | ||
| return "It's a tie!"; | ||
| } | ||
|
|
||
| }; | ||
|
|
||
|
|
||
|
|
||
| function getPrompt() { | ||
| rl.question('hand1: ', (answer1) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameters that are being used is hand1 and hand2. The function is also not closed.