-
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]: Rock Paper Scissor Game Code #14
base: main
Are you sure you want to change the base?
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,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Rock Paper Scissor</title> | ||
<link rel="stylesheet" href="./styles.css"/> | ||
|
||
</head> | ||
<body> | ||
<h1>ROCK PAPER SCISSOR GAMEPLAY</h1> | ||
<p id="user_score">YOUR SCORE : <span id="user_score_display">0</span></p> | ||
<p id="comp_score">COMPUTER SCORE : <span id="comp_score_display">0</span></p> | ||
<p id="result"></p> | ||
<button type="button" id="rock" onclick="check('rock')"><img src="./images/fist.png"/></button> | ||
<button type="button" id="paper" onclick="check('paper')"><img src="./images/hello.png"/></button> | ||
<button type="button" id="scissor" onclick="check('scissor')"><img src="./images/peace.png"/></button> | ||
|
||
|
||
<script src="index.js"></script> | ||
</body> | ||
</html> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var comp_score = 0; | ||
var user_score = 0; | ||
|
||
|
||
function check(str) { | ||
var vals = ['rock', 'paper', 'scissor']; | ||
var index = Math.floor((Math.random() * 3)); | ||
var comp_res = vals[index]; | ||
|
||
if (str == comp_res) { | ||
document.getElementById('result').innerHTML="Draw!"; | ||
} | ||
else if(str == 'rock' && comp_res == 'scissor') { | ||
document.getElementById('result').innerHTML='You Won'; | ||
user_score += 1; | ||
document.getElementById('user_score_display').innerHTML=user_score; | ||
} | ||
else if(str == 'paper' && comp_res == 'rock') { | ||
document.getElementById('result').innerHTML='You Won'; | ||
user_score += 1; | ||
document.getElementById('user_score_display').innerHTML=user_score; | ||
} | ||
else if(str == 'scissor' && comp_res == 'paper') { | ||
document.getElementById('result').innerHTML="You Won"; | ||
user_score += 1; | ||
document.getElementById('user_score_display').innerHTML=user_score; | ||
} | ||
else { | ||
document.getElementById('result').innerHTML='You Lose'; | ||
comp_score += 1; | ||
document.getElementById('comp_score_display').innerHTML=comp_score; | ||
} | ||
Comment on lines
+10
to
+32
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. instead of multiple if..else statemets and repeating code section use concept of ternary operator: |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
body { | ||
text-align: center; | ||
font-family: 'Courier New', Courier, monospace; | ||
} | ||
|
||
h1 { | ||
font-size: 4rem; | ||
} | ||
|
||
button { | ||
height: 10rem; | ||
width: 10rem; | ||
border-radius: 2rem; | ||
overflow: visible; | ||
margin: 2rem; | ||
padding: 2rem; | ||
background-color:antiquewhite; | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
max-height: 100%; | ||
} | ||
|
||
|
||
/* styles of ids */ | ||
#user_score { | ||
display: inline-block ; | ||
font-size: 2.5rem; | ||
margin: 4rem 1rem 4rem 2rem; | ||
} | ||
|
||
#comp_score { | ||
display: inline-block; | ||
font-size: 2.5rem; | ||
margin: 4rem 1rem 4rem 4rem; | ||
} | ||
|
||
#result { | ||
font-size: 1.5rem; | ||
} | ||
|
||
|
||
/* hovering effect */ | ||
button:hover { | ||
background-color:burlywood; | ||
} |
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.
remove unnecessary spacings.