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

[ADD] RPS game #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

temo-odoo
Copy link

This is a game created by me - temo

Comment on lines +33 to +44
(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++ : "";

Copy link
Owner

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++;

Copy link
Author

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">
Copy link
Owner

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.

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