-
Notifications
You must be signed in to change notification settings - Fork 14
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <title>Rock,Paper and Scissor</title> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> | ||
|
|
||
| <script src="./main.js"></script> | ||
|
|
||
| </head> | ||
|
|
||
| <body> | ||
| <div class="container"> | ||
| <div class="page-header"> | ||
| <center> | ||
| <h1>Rock, Paper and Scissor</h1> | ||
| </center> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="col-sm-6"> | ||
| <div class="h2" id="print_result">Let's Play</div> | ||
| </div> | ||
| <div class="col-sm-6"> | ||
| <h3><center>Result</center></h3> | ||
| <table class="table"> | ||
| <thead> | ||
| <tr> | ||
| <td>Win</td> | ||
| <td>Lose</td> | ||
| <td>Tie</td> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td id="win">0</td> | ||
| <td id="lose">0</td> | ||
| <td id="tie">0</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </div> | ||
| <center> | ||
| <input type="button" id="button_rock" value="Rock" onclick="ABC('rock')" /> | ||
| <input type="button" id="button_paper" value="Paper" onclick="ABC('paper')" /> | ||
| <input type="button" id="button_scissor" value="scissor" onclick="ABC('scissor')" /> | ||
| </center> | ||
| </div> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| const arr = ['rock', 'paper', 'scissor']; | ||
| let wins = 0; | ||
| let losses = 0; | ||
| let ties = 0; | ||
|
|
||
| function ABC(value) { | ||
| var rand = arr[Math.floor(Math.random() * 3)]; | ||
| document.getElementById("print_result").innerHTML = `You choose ${value}, computer choose ${rand}.<br/><br/>`; | ||
|
|
||
| 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.
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