-
Notifications
You must be signed in to change notification settings - Fork 348
scissors paper stone basics 11-5 #344
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: main
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 |
|---|---|---|
| @@ -1,4 +1,59 @@ | ||
| // 1. Generate random object: Scissors, Paper or Stone | ||
| var rollScissorPaperStone = function () { | ||
| var randomDecimal = Math.random() * 3; | ||
| var randomInteger = Math.floor(randomDecimal); | ||
| var signRolled = 0; | ||
| if (randomInteger == 0) { | ||
| signRolled = `scissors`; | ||
| } | ||
| if (randomInteger == 1) { | ||
| signRolled = `paper`; | ||
| } | ||
| if (randomInteger == 2) { | ||
| signRolled = `stone`; | ||
| } | ||
| return signRolled; | ||
| }; | ||
|
|
||
| const signs = [`scissors`, `paper`, `stone`]; | ||
|
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 trying this out in advance, could have been used for assigning signedRolled in rollScissorsPaper stone function |
||
| var gamesCount = 0; | ||
| var userWonCount = 0; | ||
| var CompWonCount = 0; | ||
|
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. should follow camel-case convention just like your other variables |
||
| var drawCount = 0; | ||
|
|
||
| var main = function (input) { | ||
| var myOutputValue = 'hello world'; | ||
| var randomSign = rollScissorPaperStone(); | ||
| console.log(`computer generated ${randomSign}`); | ||
|
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. good use of console logs |
||
| var myOutputValue = `Uh oh, I cannot read your message. <br> | ||
|
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. input validation 👍 |
||
| Please type one of the 3 options: scissors, paper or stone`; | ||
|
|
||
| // Outcome 1: Player and Computer draw | ||
| if (input == randomSign) { | ||
| gamesCount += 1; | ||
| drawCount += 1; | ||
| myOutputValue = `You chose ${input}. <br> The computer chose ${randomSign}. <br> You drawed ${drawCount} times. <br> Type "scissors" "paper" or "stone" to play another round!`; | ||
| } | ||
|
Comment on lines
+31
to
+35
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. good job figuring this out |
||
|
|
||
| // Outcome 2: Player lost, Computer wins | ||
| if ( | ||
| (input == signs[0] && randomSign == signs[2]) || | ||
| (input == signs[1] && randomSign == signs[0]) || | ||
| (input == signs[2] && randomSign == signs[1]) | ||
| ) { | ||
| gamesCount += 1; | ||
| CompWonCount += 1; | ||
| myOutputValue = `You chose ${input}. <br> Computer chose ${randomSign}. <br> You lost ${CompWonCount} out of ${gamesCount} games, and drawed ${drawCount} times. Keep trying! <br> Type "scissors" "paper" or "stone" to play another round!`; | ||
| } | ||
|
|
||
| // Outcome 3: Player wins, Computer lost | ||
| if ( | ||
| (input == signs[0] && randomSign == signs[1]) || | ||
| (input == signs[1] && randomSign == signs[2]) || | ||
| (input == signs[2] && randomSign == signs[0]) | ||
| ) { | ||
| gamesCount += 1; | ||
| userWonCount += 1; | ||
| myOutputValue = `You chose ${input}. Computer chose ${randomSign}. <br> You won ${userWonCount} out of ${gamesCount} games, and drawed ${drawCount} times. Feeling lucky? <br> Type "scissors" "paper" or "stone" to play another round!`; | ||
| } | ||
| return myOutputValue; | ||
| }; | ||
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.
gd job abstracting this out into a function