-
Notifications
You must be signed in to change notification settings - Fork 348
Tricia Basics 11-10 #338
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: main
Are you sure you want to change the base?
Tricia Basics 11-10 #338
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 |
|---|---|---|
| @@ -1,4 +1,59 @@ | ||
| var main = function (input) { | ||
| var myOutputValue = 'hello world'; | ||
| return myOutputValue; | ||
| // this is a basic version of scissors paper stone // | ||
| // scissors beats paper // | ||
| // paper beats stone // | ||
| // stone beats scissors // | ||
| // if both parties choose the same object, it is a draw // | ||
| // user chooses input as scissors paper or stone // | ||
| // randomly return one of scissors paper or stone // | ||
|
|
||
| var generateMove = function () { | ||
| // Generate random number between 1 and 3 // | ||
| var numPossibleMoves = 3; | ||
| var randomNum = Math.floor(Math.random() * numPossibleMoves) + 1; | ||
|
|
||
| // Return the word that corresponds to the relevant number // | ||
| if (randomNum == 1) { | ||
| return "scissors"; | ||
| } | ||
| if (randomNum == 2) { | ||
| return "paper"; | ||
| } | ||
| return "stone"; | ||
| }; | ||
|
Comment on lines
+9
to
+22
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. [Comment] Good job to separate out this function by itself. |
||
|
|
||
| var main = function (userMove) { | ||
| var move = generateMove(); | ||
| var standardMessage = `You played: ${userMove}. Computer played: ${move}.`; | ||
| // if both parties choose the same object, it is a draw // | ||
| if (move == userMove) { | ||
| return `${standardMessage} <br> <br> It's a draw! Please play again.`; | ||
| } | ||
| // scissors beats 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. [Comment] Nice comments to show what the code is doing |
||
| if (move == "scissors" && userMove == "paper") { | ||
| return `${standardMessage} <br> <br> You lost! Please play again.`; | ||
| } | ||
| // paper beats stone // | ||
| if (move == "paper" && userMove == "stone") { | ||
| return `${standardMessage} <br> <br> You lost! Please play again.`; | ||
| } | ||
| // stone beats scissors // | ||
| if (move == "stone" && userMove == "scissors") { | ||
| return `${standardMessage} <br> <br> You lost! Please play again.`; | ||
| } | ||
| // scissors beats paper // | ||
| if (userMove == "scissors" && move == "paper") { | ||
| return `${standardMessage} <br> <br> You won! Please play again.`; | ||
| } | ||
| // paper beats stone // | ||
| if (userMove == "paper" && move == "stone") { | ||
| return `${standardMessage} <br> <br> You won! Please play again.`; | ||
| } | ||
|
Comment on lines
+40
to
+50
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. [Suggestion]: You could have combined some of these IF conditions. Using || to combine all the losing cases. This would simplify your code. |
||
| // stone beats scissors // | ||
| if (userMove == "stone" && move == "scissors") { | ||
| return `${standardMessage} <br> <br> You won! Please play again.`; | ||
| } | ||
| // if user puts in undefined move // | ||
| if (userMove != "scissors" || "paper" || "stone") { | ||
| return `Your move is not valid! <br> <br> To play, please enter scissors, paper, or stone`; | ||
| } | ||
| }; | ||
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.
[Comment] Nice use of pseudo code