From 12d06ac8832c6a235fca35f878655f5b8cb03321 Mon Sep 17 00:00:00 2001 From: epidemicflu Date: Wed, 21 Oct 2015 21:25:16 +0000 Subject: [PATCH] finished assignment.still needs some styling --- starter_code/index.html | 2 ++ starter_code/script.js | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/starter_code/index.html b/starter_code/index.html index a2f6656..d8f2504 100755 --- a/starter_code/index.html +++ b/starter_code/index.html @@ -10,6 +10,8 @@ + + diff --git a/starter_code/script.js b/starter_code/script.js index 839d178..789f28c 100755 --- a/starter_code/script.js +++ b/starter_code/script.js @@ -4,17 +4,41 @@ 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 'scissors'; + } + return 'paper'; + } // 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'; + } + // && and + // || or + if(userValue === 'rock' && aiValue === 'scissors' || + userValue === 'paper' && aiValue === 'rock' || + userValue === 'scissors' && aiValue === 'paper'){ + userPoint++ + return 'user' + } + aiPoint += 1; + return 'ai' + } // 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