Skip to content

SPS project submission#357

Open
yiuhankit wants to merge 1 commit into
rocketacademy:mainfrom
yiuhankit:main
Open

SPS project submission#357
yiuhankit wants to merge 1 commit into
rocketacademy:mainfrom
yiuhankit:main

Conversation

@yiuhankit

Copy link
Copy Markdown

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?

Comment thread script.js
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of pseudocode for formulating your thoughts before coding

Comment thread script.js
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!`;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 gcskhor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants