Implementing a rps game which is based on javascript#13
Implementing a rps game which is based on javascript#13gusi-odoo wants to merge 2 commits intoshsa-odoo:mainfrom
Conversation
Rock_paper_scissors/main.js
Outdated
| let losses = 0; | ||
| let ties = 0; | ||
|
|
||
| function ABC(value) { |
There was a problem hiding this comment.
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.
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.
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