Skip to content
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

Completed Homework Assignment #4 - Caleb Sanchez #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cswebdesign
Copy link

  1. Rock, Paper, Scissors game where Bot randomly makes selection
  2. Winner is awarded a point and scoreboard is dynamically updated
  3. If a player wins 3 times in a row they are awarded 2 bonus points
  4. If a player reaches 10 points they win the 1st round and color scheme is updated
  5. If a player reaches 20 points they win the whole game and color scheme is updated
  6. Reset button resets the game

*The consecutive win option was an awesome problem that had me frustrated for awhile. The solution ended up being far more simple than what I started with.

Copy link

@aghaffar570 aghaffar570 left a comment

Choose a reason for hiding this comment

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

Great work on the rock-scissor-paper game!

Comment on lines +26 to +37
botChoice = Math.floor(Math.random() * 3) + 1

//If statement to assign numbers to string choices
if (botChoice === 1) {
botChoice = 'rock'
} else if (botChoice === 2) {
botChoice = 'scissors'
} else if (botChoice === 3) {
botChoice = 'paper'
} else {
console.log('Invalid choice.')
}

Choose a reason for hiding this comment

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

@cswebdesign botChoice will either be 1, 2, or 3. if it's not 1 or 2, then we can assume it'll be 3, so line 33 could be replaced with a simple else statement. line 35 will never run, but it's great that you're thinking about edge cases and error handling. 👍

An alternative solution could be to store the choices in an array and access them via index (minus the 1).
check solution here

//Function to compare choices, declare a winner, and reward points
function determineWinner() {
if ( userChoice === botChoice ) {
$('#status').html(`<p>You chose <b><u>${userChoice}</u></b>. The bot chose <b><u>${botChoice}</u></b>.</p><p>Tie game!</p>`)

Choose a reason for hiding this comment

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

@cswebdesign the only part that changes in the status is the userChoice and botChoice. Because the string is used several times, you may want to consider encapsulating it into a function.

Here is the alternative approach

Comment on lines +100 to +114
function roundOneWinner() {
if(botScore >= 10) {
$('#wise-message').text('Round 1 Winner: Bot')
$('body').css('color', 'yellow')
$('button').css('background', 'yellow')
$('.scoreboard').css('borderColor', 'yellow')
$('.scoreboard h2').css('borderBottomColor', 'yellow')
} else if(userScore >= 10) {
$('#wise-message').text('Round 1 Winner: You')
$('body').css('color', 'yellow')
$('button').css('background', 'yellow')
$('.scoreboard').css('borderColor', 'yellow')
$('.scoreboard h2').css('borderBottomColor', 'yellow')
}
}

Choose a reason for hiding this comment

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

@cswebdesign Great job on breaking each logical portion into separate functions. To conform to the DRY principle and get the most out of the functions, consider passing arguments through so it can be extended in other parts of your code. This can be reused in the roundTwoWinner function, but there are certainly many ways to solve this.

Great effort on the extra features!! 🥇

check the solution for how things are being compared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants