Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 53 additions & 0 deletions Rock_paper_scissors/index.html
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="gameState('rock')" />
<input type="button" id="button_paper" value="Paper" onclick="gameState('paper')" />
<input type="button" id="button_scissor" value="scissor" onclick="gameState('scissor')" />
</center>
</div>
</body>

</html>
16 changes: 16 additions & 0 deletions Rock_paper_scissors/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const arr = ['rock', 'paper', 'scissor'];
let wins = 0;
let losses = 0;
let ties = 0;

function gameState(value) {
var rand = arr[Math.floor(Math.random() * 3)];
document.getElementById("print_result").innerHTML = `You choose ${value}, computer choose ${rand}.<br/><br/>`;
let you_win = ((value == 'rock' && rand == "scissor") || (value == "paper" && rand == "rock") || (value == "scissor" && rand == "paper"))
let computer_win = (value == 'rock' && value == "scissor" || rand == "paper" && value == "rock" || rand == "scissor" && value == "paper")
document.getElementById("print_result").innerHTML += (you_win) ? `You Win` : (value === rand) ? `it's a Tie` : `Computer Win`
incrementScore(you_win,computer_win)
}
const incrementScore = ((user,computer) => {
user ? document.getElementById("win").innerHTML = wins += 1 : computer ? document.getElementById("lose").innerHTML = losses += 1 : document.getElementById("tie").innerHTML = ties +=1;
});