Skip to content

Commit d37f26b

Browse files
Merge pull request #27 from yash06112002/master
New Project Added https://github.com/swapnilsparsh/30DaysOfJavaScript…
2 parents bb75554 + c2ab8eb commit d37f26b

File tree

9 files changed

+131
-0
lines changed

9 files changed

+131
-0
lines changed

30DaysOfJavaScript/assets/37.png

146 KB
Loading

37 - RPS Game/assets/images1.png

5.93 KB
Loading

37 - RPS Game/assets/images2.png

6.64 KB
Loading

37 - RPS Game/assets/images3.png

4.05 KB
Loading

37 - RPS Game/fonts/sans.ttf

54.5 KB
Binary file not shown.

37 - RPS Game/start.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
<link rel="stylesheet" href="style.css">
9+
<script src="start.js"></script>
10+
</head>
11+
<body>
12+
<div class="container">
13+
<div>
14+
<h2> Stone Paper Scissors Game</h2><br>
15+
<img id="Rock" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQMm_CG8rW0lcRsU44OEJ72i9Fqgl8e65dOzTA2CNl7M7urmaAEvWSMzhrO9UXQI87PQHg&usqp=CAU" alt="Rock" height="150px" width="150px" onclick="rpsGame(id)">
16+
<img id="Paper" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTq5coVBzk-fBpsBg0mH5IHjE-z7wsSyO6LAnaGPRp5KOsySVwfH89a3vj1qI92tmIKP1Q&usqp=CAU" alt="Paper"
17+
height="150px" width="150px" onclick="rpsGame(id)">
18+
<img id="Scissors" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT4KAZtQUpeqelxjO89TJxMfAFtWsX1SCIwCXNaY3HNhfKSy5WTZKEF4K5nWX7upL5NvKo&usqp=CAU"alt="Scissors"
19+
height="150px" width="150px" onclick="rpsGame(id)">
20+
</div>
21+
22+
</div>
23+
24+
<div id="message">
25+
26+
</div>
27+
</body>
28+
</html>

37 - RPS Game/start.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
function rpsGame(humanChoice) {
2+
3+
let myChoice = number(humanChoice);
4+
let comChoice = random();
5+
6+
let final=result(myChoice,comChoice);
7+
8+
9+
document.getElementById("message").innerHTML=`Human choice is ${str(myChoice)} and Computer choice is ${str(comChoice)} <br> ${final}`;
10+
11+
}
12+
13+
function random() {
14+
return Math.floor(Math.random() * 3);
15+
}
16+
17+
function number(word) {
18+
if (word == "Rock") {
19+
return 0;
20+
}
21+
else if (word == "Paper") {
22+
return 1;
23+
}
24+
else if (word == "Scissors") {
25+
return 2;
26+
}
27+
}
28+
29+
function str(number) {
30+
if (number == 0) {
31+
return "Rock";
32+
}
33+
else if (number == 1) {
34+
return "Paper";
35+
}
36+
else if (number == 2) {
37+
return "Scissors";
38+
}
39+
}
40+
41+
function result(myChoice, comChoice) {
42+
if (myChoice == comChoice) {
43+
return "Tied";
44+
}
45+
else {
46+
if ((comChoice == 0 && myChoice == 1)|| (comChoice ==1 && myChoice ==2) || (comChoice ==2 && myChoice ==0)) {
47+
return "You won";
48+
}
49+
else if ((comChoice == 1 && myChoice == 0)|| (comChoice ==2 && myChoice ==1) || (comChoice ==0 && myChoice ==2)) {
50+
return "Computer won";
51+
}
52+
}
53+
}

37 - RPS Game/style.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
body{
2+
background-color: #19172e;
3+
font-family: 'sans';
4+
}
5+
6+
h2
7+
{
8+
font-style: oblique;
9+
color: #fff;
10+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11+
text-align: center;
12+
font-size: 40px;
13+
padding: 0%;
14+
}
15+
16+
img:hover
17+
{
18+
box-shadow: rgb(95, 9, 26) 10px 10px 10px;
19+
}
20+
21+
img
22+
{
23+
box-shadow: crimson -10px -10px 10px;
24+
margin: 40px;
25+
}
26+
27+
.container
28+
{
29+
max-width: 700px;
30+
align-items: center;
31+
justify-content: center;
32+
margin: auto;
33+
display: flex;
34+
border: 5px solid #fff;
35+
padding: 10px;
36+
}
37+
#message{
38+
text-align: center;
39+
font-size: 50px;
40+
41+
color: #fff;
42+
}

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ <h4>Hangman</h4>
257257
<img src="30DaysOfJavaScript/assets/36.png" alt="Hangman" />
258258
</a>
259259
</div>
260+
261+
<div class="item">
262+
<a target="_blank" href="37 - RPS Game/start.html">
263+
<h4>Rock Paper Scissors Game</h4>
264+
<img src="30DaysOfJavaScript/assets/37.png" alt="Rock Paper Scissors Game" />
265+
</a>
266+
</div>
267+
260268
</div>
261269
</div>
262270

0 commit comments

Comments
 (0)