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
11 changes: 7 additions & 4 deletions starter_code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
<head>
<title>
<!-- Enter a title for your game here -->
<title> Rock, Paper or Scissors</title>
</title>
<!-- Link CSS here -->

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

<script src="https://code.jquery.com/jquery-2.1.4.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="rock" class="token" value="Rock"><img src="Rock.png"/></div>
<div id="paper" class="token" value="Paper"><img src="Paper.png"/></div>
Copy link
Member

Choose a reason for hiding this comment

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

a div with a value attribute? pour que?

<!-- Create Scissors option here -->
<div id="scissors" class="token" value="Scissors"><img src="Scissor.png"/></div>
</div>

<div class="container">
Expand Down
34 changes: 32 additions & 2 deletions starter_code/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,44 @@ var aiPoint = 0;
// This function returns the selection of the computer
function getAISelection() {
//TODO: randomly choose between 'rock', 'paper', or 'scissors'
var random = Math.floor(Math.random * 3);
var choices = ["Rock", "Paper", "Scissors"];
return choices[random];
Copy link
Member

Choose a reason for hiding this comment

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

awesome! just don't forget to invoke Math.random ;)

}

// 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";
} else if(userValue == "Rock"){
if(aiValue == "Paper"){
return "cpu";
} else {
return "user";
}
} else if(userValue == "Paper"){
if(aiValue == "Scissors"){
return "cpu";
} else {
return "user";
}
} else if(userValue == "Scissors"){
if(aiValue == "Rock"){
return "cpu";
} else {
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.

slick if statement

}
}

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

var userText = $('#userPoint');
userText.text(userPoint);
var aiText = $('#aiPoint');
aiText.text(aiPoint);
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! but just cause i have to be a stickler, why store the element in a var if we're only using it once? $('#aiPoint').text(aiPoint) is just as valid

}

// This function captures the click and picks the winner
Expand All @@ -26,14 +53,17 @@ function evaluate(evt) {

if ( 'user' === winner ) {
$('#message').delay(50).text('You have won!, Click a box to play again');
userPoint ++;
} else if ( winner === 'draw' ) {
$('#message').delay(50).text('Draw! Click a box to play again');
} else {
$('#message').delay(50).text('You have lost!, Click a box to play again');
aiPoint++;
}
setScore();
}

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

Copy link
Member

Choose a reason for hiding this comment

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

seems like you're only missing binding the evaluate function to the click event

});
4 changes: 4 additions & 0 deletions starter_code/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
}
#message {
text-align: center;
}
.token img{
Copy link
Member

Choose a reason for hiding this comment

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

noice!

width: 200px;
height: 200px;
}