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: 3 additions & 3 deletions starter_code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<title>
<!-- Enter a title for your game here -->
</title>
<!-- Link CSS here -->
<link href="style.css" rel="stylesheet" type="text/css" />

<!-- Link JQuery here -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"></script>

<!-- Link script.js here -->
<script src="script.js"></script>
</head>

<body>
Expand Down
18 changes: 17 additions & 1 deletion starter_code/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@ var aiPoint = 0;

// This function returns the selection of the computer
function getAISelection() {
//TODO: randomly choose between 'rock', 'paper', or 'scissors'
var options = ["rock","scissors","paper"];
var random = Math.floor(Math.random() * (0 - 3 + 1)) + 0;
return options[random];
Copy link
Member

Choose a reason for hiding this comment

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

This looks promising. just make sure to review the number you assign into random, it's a little off. (btw, you can have negative nums in JS too, like -3)

}

// 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 == "rock" && aiValue == "paper"){
return "winner";
userPoint += 1;
Copy link
Member

Choose a reason for hiding this comment

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

if you return before incrementing the counter, it will never be incremented 😭

}else if(userValue == "scissors" && aiValue == "paper"){
return "winner";
userPoint += 1;
}else if(userValue == "paper" && aiValue == "rock"){
return "winner";
userPoint += 1;
}else if(userValue == aiValue){
return "draw";
}else{
aiPoint += 1;
}
}

// This function sets the scoreboard with the correct points
Expand Down