-
Notifications
You must be signed in to change notification settings - Fork 15
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
[ADD] RPS game #12
base: main
Are you sure you want to change the base?
[ADD] RPS game #12
Conversation
(x == computer_value) ? "" : "" ; | ||
|
||
(x == 0 && computer_value== 1) ? computer++ : ""; | ||
(x == 0 && computer_value== 2) ? me++ : ""; | ||
|
||
(x == 1 && computer_value== 0) ? me++ : ""; | ||
(x == 1 && computer_value== 2) ? computer++ : ""; | ||
|
||
|
||
(x == 2 && computer_value== 0) ? computer++ : ""; | ||
(x == 2 && computer_value== 1) ? me++ : ""; | ||
|
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 code. here you can use nested ternary operator:
what i can see is there are only three cases when you can win:
you_win = ( (you === 0) && (opponent === 2) ||
(you === 1) && (opponent === 0) ||
(you === 2) && (opponent === 1) ) // returns true for your win cases only.
.
.
so (you === opponent) ? "draw message" : you_win ? you ++ : opponent++;
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.
I will update my code sir . Thank you sir
</div> | ||
</div> | ||
|
||
<script type="text/javascript"> |
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.
Make a separate file for JS.
avoid putting your code to script tags.
This is a game created by me - temo