-
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
Changes from all commits
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> | ||
<link rel="stylesheet" href="style.css" type="text/css"/> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="screen"> | ||
<div class="buttons"> | ||
<button onclick="game(0)">Rock</button> | ||
<button onclick="game(1)">Paper</button> | ||
<button onclick="game(2)">Scissor</button> | ||
</div> | ||
<h1 id="computer">Computer</h1> | ||
</div> | ||
<div> | ||
<p class="me">Me: <span id="me_score">0</span></p> | ||
<p class="comp">Computer: <span id="computer_score">0</span></p> | ||
</div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
|
||
var me =0; | ||
var computer=0; | ||
|
||
function game(x) { | ||
var list =["Rock","Paper","Scissor"] | ||
|
||
var computer_value= Math.floor(Math.random()*3); | ||
document.getElementById('computer').innerHTML=list[computer_value]; | ||
|
||
(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++ : ""; | ||
|
||
Comment on lines
+33
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid using repetitive code. here you can use nested ternary operator: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will update my code sir . Thank you sir |
||
document.getElementById('me_score').innerHTML=me; | ||
document.getElementById('computer_score').innerHTML=computer; | ||
} | ||
</script> | ||
|
||
|
||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family: 'Poppins',sans-serif; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
width: 480px; | ||
margin: auto; | ||
padding-top: 120px; | ||
|
||
|
||
} | ||
|
||
.screen { | ||
display: flex; | ||
} | ||
|
||
.buttons , #computer { | ||
margin: 2px; | ||
flex-basis: 50%; | ||
height: 210px; | ||
background-color: lightblue; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
button{ | ||
font-size: 18px; | ||
padding: 8px; | ||
} | ||
|
||
button:focus{ | ||
font-weight: bold; | ||
} | ||
|
||
.me{float: left;} | ||
|
||
.comp{float: right;} |
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.