From 60e390937e687988d619dbfd5e0dc54450d3f187 Mon Sep 17 00:00:00 2001 From: shirokane Date: Wed, 21 Oct 2015 21:30:35 +0000 Subject: [PATCH] yahallo --- starter_code/index.html | 6 +++--- starter_code/script.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/starter_code/index.html b/starter_code/index.html index a2f6656..ccda246 100755 --- a/starter_code/index.html +++ b/starter_code/index.html @@ -5,11 +5,11 @@ <!-- Enter a title for your game here --> - + - + - + diff --git a/starter_code/script.js b/starter_code/script.js index 839d178..63ddab4 100755 --- a/starter_code/script.js +++ b/starter_code/script.js @@ -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]; } // 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; + }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