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
6 changes: 4 additions & 2 deletions starter_code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
<!-- Enter a title for your game here -->
</title>
<!-- Link CSS here -->

<link rel="stylesheet" href="style.css">
<!-- Link JQuery here -->

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Link script.js here -->
<script src="script.js"></script>
</head>

<body>

<div class="container">
<div id="rock" class="token">ROCK</div>
<div id="paper" class="token">PAPER</div>
<div id="scissor" class="token">SCISSOR</div>
<!-- Create Scissors option here -->
</div>

Expand Down
41 changes: 37 additions & 4 deletions starter_code/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,48 @@ var aiPoint = 0;

// This function returns the selection of the computer
function getAISelection() {
//TODO: randomly choose between 'rock', 'paper', or 'scissors'
var random = Math.random();
if(random < 1/3){
return 'rock';
}

if (random < 2/3){
return 'scissor';
}

return 'paper';
Copy link
Member

Choose a reason for hiding this comment

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

nice!


}

// This function picks the winner
function pickWinner(userValue, aiValue) {
//TODO: pick the correct winner: user or ai
//TODO: Add one point for the winner
if(userValue === aiValue){
return 'draw';
}

if(userValue === 'rock' && aiValue === 'paper' ||
userValue === 'paper' && aiValue === 'scissor' ||
userValue === 'scissor' && aiValue === 'rock'){
aiPoint++;
return 'AI WINS!!!'
}

if(userValue === 'paper' && aiValue === 'rock' ||
userValue === 'rock' && aiValue === 'scissor' ||
userValue === 'scissor' && aiValue === 'paper'){
userPoint++;
return 'user';
}
Copy link
Member

Choose a reason for hiding this comment

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

hmm, if its not a tie, and the winner is not AI, then do we have to check again before just returning user?



}

// This function sets the scoreboard with the correct points
function setScore() {

$('#userPoint').text(userPoint);
$('#aiPoint').text(aiPoint);
}

// This function captures the click and picks the winner
Expand All @@ -23,7 +53,9 @@ function evaluate(evt) {
var aiValue = getAISelection();

var winner = pickWinner(userValue, aiValue);


setScore();

if ( 'user' === winner ) {
$('#message').delay(50).text('You have won!, Click a box to play again');
} else if ( winner === 'draw' ) {
Expand All @@ -35,5 +67,6 @@ function evaluate(evt) {

// This function runs on page load
$(document).ready(function(){

setScore();
$('.token').on('click', evaluate);
});
23 changes: 23 additions & 0 deletions starter_code/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,30 @@
text-align: center;
padding: 50px 0px 50px 0px;
font-size: x-large;

}

#rock{
background-image: url("Rock.png");
background-size: 60px;
background-repeat: no-repeat;
background-position: center;
}

#paper{
background-image: url("Paper.png");
background-size: 60px;
background-repeat: no-repeat;
background-position: center;
}

#scissor{
background-image: url("Scissor.png");
background-size: 45px;
background-repeat: no-repeat;
background-position: center;
}
Copy link
Member

Choose a reason for hiding this comment

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

very nice!


#message {
text-align: center;
}