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

intial task of rps game #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dhrs-odoo
Copy link

intial task of javascript (rps game)

Comment on lines 28 to 62
if (you == opponent) {
alert('Its a tie')
}
else {
if (you == "rock") {
if (opponent == "scissors") {
alert('yuppie😀 you got a point')
yourScore += 1;
}
else if (opponent == "paper") {
alert('shit😣 opponent got a point')
opponentScore += 1;
}
}
else if (you == "scissors") {
if (opponent == "paper") {
alert('yuppie😀 you got a point')
yourScore += 1;
}
else if (opponent == "rock") {
alert('shit😣 opponent got a point')
opponentScore += 1;
}
}
else if (you == "paper") {
if (opponent == "rock") {
alert('yuppie😀 you got a point')
yourScore += 1;
}
else if (opponent == "scissors") {
alert('shit😣 opponent got a point')
opponentScore += 1;
}
}
}
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 multiple if..else and 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