-
Notifications
You must be signed in to change notification settings - Fork 15
Implementing a rps game which is based on javascript #13
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
base: main
Are you sure you want to change the base?
Conversation
Rock_paper_scissors/main.js
Outdated
let losses = 0; | ||
let ties = 0; | ||
|
||
function ABC(value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always use a better naming convention that represent the property of you code:
instead of ABC , use gameState/ updateStatus ... etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry sir next time i will take care of this
Rock_paper_scissors/main.js
Outdated
if (value == 'rock' && rand == "scissor" || | ||
value == "paper" && rand == "rock" || | ||
value == "scissor" && rand == "paper") { | ||
document.getElementById("win").innerHTML = wins += 1; | ||
document.getElementById("print_result").innerHTML += `You Win`; | ||
|
||
} else if (rand == 'rock' && value == "scissor" || | ||
rand == "paper" && value == "rock" || | ||
rand == "scissor" && value == "paper") { | ||
document.getElementById("lose").innerHTML = losses += 1; | ||
document.getElementById("print_result").innerHTML += `Computer Win`; | ||
|
||
} else { | ||
document.getElementById("tie").innerHTML = ties += 1; | ||
document.getElementById("print_result").innerHTML += `it's a Tie`; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using repetitive piece of code, store it in one variable and use it, here
update the code using ternary operator instead of if..else
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;
Rock Paper Scissor game in js