Skip to content

Conversation

@yava-odoo
Copy link

Created Rock,Paper and Scissors game

Comment on lines +33 to +53
if (user_choice == comp_choice) {
result_text.textContent = "It's Draw";
} else if (
(user_choice == "rock") & (comp_choice == "scissors") ||
(user_choice == "paper") & (comp_choice == "rock") ||
(user_choice == "scissors") & (comp_choice == "paper")
) {
player_score++;
user_win_count.innerText = player_score;
result_text.textContent = "You Win";

} else if (
(user_choice == "rock") & (comp_choice == "paper") ||
(user_choice == "paper") & (comp_choice == "scissors") ||
(user_choice == "scissors") & (comp_choice == "rock")
) {
computer_score++;
computer_win_count.innerText = computer_score;
result_text.textContent = "You Lose";

}
Copy link
Owner

Choose a reason for hiding this comment

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

update this code using ternary operator, avoid using repeating statements,
what i can see is there are only three cases when user can win:
you_win = ( (you === "rock") && (opponent === "scissor") ||
(you === "paper") && (opponent === "rock") ||
(you === "scissor") && (opponent === "rock") ) // returns true for your win cases only.
.
.
so (you === opponent) ? "draw message" : you_win ? call a method for updating score and message for user : call method for updating score and message fro computer;

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