Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions task1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
*,
*:Before,
*:After{
Padding: 0;
Margin: 0;
Box-Sizing: Border-Box;
}
Body{
Height: 100vh;
Background: Linear-Gradient(
135deg,
#1bcaff,
#231bff
);
}
.Container{
Width: 45%;
Min-Width: 500px;
Background-Color: #Ffffff;
Padding: 40px 30px;
Position: Absolute;
Transform: Translate(-50%,-50%);
Top: 50%;
Left: 50%;
Border-Radius: 10px;
Box-Shadow: 0 15px 25px Rgba(0,0,0,0.15);
}
.Scores{
Margin-Bottom: 50px;
Text-Align: Right;
}
.Details{
Margin-Top: 30px;
Text-Align: Center;
}
.Scores,.Details{
Font-Family: 'Poppins',Sans-Serif;
Font-Weight: 400;
Font-Size: 15px;
}

#User_choice,
#Computer_choice{
Font-Weight: 400;
Margin-Bottom: 10px;
}
Span{
Font-Weight: 600;
}




.btn {
border: 2px solid black;
background-color: white;
color: black;
padding: 14px 28px;
font-size: 16px;
cursor: pointer;
}

.success {
border-color: #04AA6D;
color: green;
}

.success:hover {
background-color: #04AA6D;
color: white;
}
/* Orange */
.warning {
border-color: #ff9800;
color: orange;
}

.warning:hover {
background: #ff9800;
color: white;
}

/* Red */
.danger {
border-color: #f44336;
color: red;
}

.danger:hover {
background: #f44336;
color: white;
}
.center {
text-align: center;
padding: 10px;
}
32 changes: 32 additions & 0 deletions task1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<Html Lang="En">
<Head>
<Title>Rock Paper Scissor Game</Title>
<!--Stylesheet-->
<Link Rel="Stylesheet" Href="task1.css">
</Head>
<Body>
<Div Class="Container">
<h1 class="center">Rock Paper & Scissor Game</h1>
<Div Class="Scores">
<P>Computer :
<Span Id="computer_score">0</Span>
</P>
<P>
You :
<span Id="user_scores">0</Span>
</P>
</Div>
<div class="center">
<h2 id="status"></h2>
</div>
<Div Class="center">
<Button type="button" Onclick="rock()" class="btn danger">Rock</Button>
<Button type="button" Onclick="paper()" class="btn success">Paper</Button>
<Button type="button" Onclick="scissor()" class="btn warning">Scissor</Button>
</Div>
</Div>
<!--Script-->
<Script Src="task1.js"></Script>
</Body>
</Html>
69 changes: 69 additions & 0 deletions task1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const choices=['Rock','Paper','Scissor'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give proper spacing while assignment:
const choices = ['Rock','Paper','Scissor'];
update it for all cases in the code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sir

var user_scores=0,computer_score=0;
function rock()
{
let computer_choice=Math.floor(Math.random() * choices.length);
console.log(choices[computer_choice])

if(choices[computer_choice]=='Rock')
{
// console.log("helllllllo")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discard the unwanted/ commeted out code while you push the code. make it a habit of checking the code you push.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sir

document.getElementById("status").textContent="Draw";
}
else if (choices[computer_choice]=='Paper')
{
document.getElementById("status").textContent="Computer Wins";
computer_score+=1;
document.getElementById("computer_score").textContent=computer_score;
console.log(computer_score)
}
else if(choices[computer_choice]=='Scissor')
{
document.getElementById("status").textContent="You Win";
user_scores+=1;
document.getElementById("user_scores").textContent=user_scores;
console.log(user_scores)
}
}
function paper()
{
let computer_choice=Math.floor(Math.random() * choices.length);
console.log(choices[computer_choice])
if(choices[computer_choice]=='Paper')
{
document.getElementById("status").textContent="Draw";
}
else if (choices[computer_choice]=='Scissor')
{
document.getElementById("status").textContent="Computer Wins";
computer_score+=1;
document.getElementById("computer_score").textContent=computer_score;
}
else if(choices[computer_choice]=='Rock')
{
document.getElementById("status").textContent="You Win";
user_scores+=1;
document.getElementById("user_scores").textContent=user_scores;
}
}
function scissor()
{
let computer_choice=Math.floor(Math.random() * choices.length);
console.log(choices[computer_choice])
if(choices[computer_choice]=='Scissor')
{
document.getElementById("status").textContent="Draw";
}
else if (choices[computer_choice]=='Rock')
{
document.getElementById("status").textContent="Computer Wins";
computer_score+=1;
document.getElementById("computer_score").textContent=computer_score;
}
else if(choices[computer_choice]=='Paper')
{
document.getElementById("status").textContent="You Win";
user_scores+=1;
document.getElementById("user_scores").textContent=user_scores;
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making separate function call for separate event is good.
But optimize the code:

  1. using ternary operator. as user can win in three cases only :
    you_win = ( (you === "rock") && (opponent === "scissor") ||
    (you === "paper") && (opponent === "rock") ||
    (you === "scissor") && (opponent === "rock") ) // returns true for your win cases only.
    .
    .
    so (you === opponent) ? "draw message" : you_win ? call a method for updating score and message for user : call method for updating score and message fro computer;

3.(note* for this case only.) use concept of querySelectorAll("button"), and foreach click call a method that update the state of your game.
4. declare it a const computer_choice=Math.floor(Math.random() * choices.length); and on every time your method calls while button click , you will get a random method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sir
I have optimize my code in today's RPS game using owl I will do it same in this code without owl