-
Notifications
You must be signed in to change notification settings - Fork 12
RockPaperScissors #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,26 +4,67 @@ 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) | ||
| if (random == 0){ | ||
| return 'rock'; | ||
| } | ||
| if (random == 1){ | ||
| return 'paper'; | ||
| } | ||
| if (random == 2){ | ||
| return 'scissors'; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
| } | ||
|
|
||
| // This function picks the winner | ||
| function pickWinner(userValue, aiValue) { | ||
| if (userValue === aiValue){ | ||
| return 'draw'; | ||
| } | ||
| if(userValue == 'rock' && aiValue == 'paper'){ | ||
| aiPoint++; | ||
| return 'Ai Wins!'; | ||
| } | ||
| if(userValue == 'paper' && aiValue == 'scissors'){ | ||
| aiPoint++; | ||
| return 'Ai Wins!'; | ||
| } | ||
| if(userValue == 'scissors' && aiValue == 'rock'){ | ||
| aiPoint++; | ||
| return 'Ai Wins!'; | ||
| } | ||
| if(userValue == 'rock' && aiValue == 'scissors'){ | ||
| userPoint++; | ||
| return 'user'; | ||
| } | ||
| if(userValue == 'paper' && aiValue == 'rock'){ | ||
| userPoint++; | ||
| return 'user'; | ||
| } | ||
| if(userValue == 'scissors' && aiValue == 'paper'){ | ||
| userPoint++; | ||
| return 'user'; | ||
| } | ||
| //TODO: pick the correct winner: user or ai | ||
| //TODO: Add one point for the winner | ||
| } | ||
|
|
||
| // 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 | ||
| function evaluate(evt) { | ||
| debugger; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neat! how's that working out for you? did you see how the browser stops execution when you run this function (and the console is open)? |
||
| var userValue = evt.target.getAttribute('id'); | ||
| 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' ) { | ||
|
|
@@ -35,5 +76,5 @@ function evaluate(evt) { | |
|
|
||
| // This function runs on page load | ||
| $(document).ready(function(){ | ||
|
|
||
| $('.token').on('click', evaluate); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great |
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont forget semicolon at the end of your expressions