SPS project submission#357
Open
yiuhankit wants to merge 1 commit into
Open
Conversation
gcskhor
reviewed
Jun 13, 2022
Comment on lines
+115
to
+135
| // user : U, com : C | ||
| // scissors = 3, paper = 2, stone = 1 | ||
|
|
||
| // NORMAL CASE 1-3 | ||
| // case 1: draw | ||
| // case 1: U choose sci(3), C choose sci(3) or any other similar | ||
| // therefore for case 1, U = C always => 0 | ||
|
|
||
| // case 2: U win | ||
| // case 2: U choose sci (3), C choose paper (2) => 1 | ||
| // case 2: U choose paper (2), C choose stone (1) => 1 | ||
| // case 2: U choose stone (1), C choose sci (3) => -2 | ||
| // therefore for case 2, U-C = 1 OR -2 | ||
|
|
||
| // case 3: C win | ||
| // case 3: U choose paper (2), C choose sci (3) => -1 | ||
| // case 3: U choose stone (1), C choose paper (2) => -1 | ||
| // case 3: U choose sci (3), C choose stone (1) => 2 | ||
| // therefore for case 2, U-C = -1 OR 2 | ||
|
|
||
| // REVERSED CASE just reverse case 2 and 3 output for reversed input |
There was a problem hiding this comment.
Great use of pseudocode for formulating your thoughts before coding
gcskhor
reviewed
Jun 13, 2022
Comment on lines
+78
to
+108
| if (isNaN(outcome)) { | ||
| // Check if input is valid | ||
| return `What was that?! <br><br> ${userName}, please input a valid choice: "scissors", "paper", or "stone"?`; | ||
| } else if (input == "scissors" || input == "paper" || input == "stone") { | ||
| totalTries += 1; | ||
| // Logic flow below - normal game | ||
|
|
||
| if (outcome == 0) { | ||
| totalDraws += 1; | ||
| myOutputValue += `It's a draw!`; | ||
| } else if (outcome == 1 || outcome == -2) { | ||
| totalWins += 1; | ||
| myOutputValue += `You won!`; | ||
| } else if (outcome == 2 || outcome == -1) { | ||
| totalLosses += 1; | ||
| myOutputValue += `You lost!`; | ||
| } | ||
| } else { | ||
| // Reversed game flow | ||
| totalTries += 1; | ||
| if (outcome == 0) { | ||
| totalDraws += 1; | ||
| myOutputValue += `It's a draw!`; | ||
| } else if (outcome == 1 || outcome == -2) { | ||
| totalLosses += 1; | ||
| myOutputValue += `You lost!`; | ||
| } else if (outcome == 2 || outcome == -1) { | ||
| totalWins += 1; | ||
| myOutputValue += `You won!`; | ||
| } | ||
| } |
There was a problem hiding this comment.
To challenge yourself, you could also abstract away this entire outcome portion of the code into a function that immediately sets the global score variables and determines the outcome message.
gcskhor
reviewed
Jun 13, 2022
gcskhor
left a comment
There was a problem hiding this comment.
Overall excellent use of helper functions. To make the code even more streamlined, something that you could do is to keep the main function as clean as possible while employing even more helper functions to enable this. E.g. leave only the gameState conditionals in:
if (gameState == 'game') { displayOutcome() } else { endGame() }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please fill out the survey before submitting the pull request. Thanks!
🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
How many hours did you spend on this assignment?
2.5hrs
Please fill in one error and/or error message you received while working on this assignment.
I keep getting "undefined" in the gray box when I input the username, even though I already put myOutputValue = "... message". Realized I didn't return myOutputValue in the next line.
What part of the assignment did you spend the most time on?
Thinking about the logic flow of the game. Instead of using math to determine the winner, I realized I could actually just list out all the separate cases, eg. (if user = "scissors" && computer = "paper", then user wins). But that will be quite long and not as scalable if there are more than just scissors/paper/stone as choices.
Comfort Level (1-5):
3
Completeness Level (1-5):
5
What did you think of this deliverable?
Interesting, I got to practice global variables and brush up on helper functions and computational logic.
Is there anything in this code that you feel pleased about?
That it works the way I want it to.
What's one aspect of your code you would like specific, elaborate feedback on?
Is there a more elegant way to express the SPS logic? Also, how to make the code more streamlined?