generated from AustinCodingAcademy/JS211_CurrentDateTimeProject
-
Notifications
You must be signed in to change notification settings - Fork 247
initial commit rps #9
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
Open
fidelis0788
wants to merge
1
commit into
AustinCodingAcademy:master
Choose a base branch
from
fidelis0788:my-branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,29 @@ | ||
| // uses strict mode so strings are not coerced, variables are not hoisted, etc... | ||
| 'use strict'; | ||
|
|
||
| // brings in the assert module for unit testing | ||
| const assert = require('assert'); | ||
| // brings in the readline module to access the command line | ||
| const readline = require('readline'); | ||
| // use the readline module to print out to the command line | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
| // the function that will be called by the unit test below | ||
| const rockPaperScissors = (hand1, hand2) => { | ||
|
|
||
| // Write code here | ||
| // Use the unit test to see what is expected | ||
| var hand1 = prompt("What is your choice ?"); | ||
| var hand2 = prompt("What about yours ?"); | ||
|
|
||
| if(hand1 == "" || hand2 =="") { | ||
| console.log("Input 1 is empty please try again") | ||
| } | ||
|
|
||
| // the first function called in the program to get an input from the user | ||
| // to run the function use the command: node main.js | ||
| // to close it ctrl + C | ||
| function getPrompt() { | ||
| rl.question('hand1: ', (answer1) => { | ||
| rl.question('hand2: ', (answer2) => { | ||
| console.log( rockPaperScissors(answer1, answer2) ); | ||
| getPrompt(); | ||
| }); | ||
| }); | ||
| else if(hand2 == ""){ | ||
| console.log("Input 2 is empty please try again") | ||
| } | ||
| else if(hand1 === hand2 && hand1,hand2 ==['rock','paper','scissors']) { | ||
|
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. the second part here is not correct. I think you are trying to verify that hand1 and hand2 are valid. |
||
| console.log ("It is a tie"); | ||
| } | ||
| else if(hand1 === "rock" && hand2 === "paper"||hand1 ==="paper" && hand2 === "scissors"){ | ||
| console.log("hand2 wins"); | ||
| } | ||
| else if(hand1 === "rock" && hand2 === "scissors") { | ||
| console.log("hand1 wins") | ||
| } | ||
| else{ | ||
| console.log('try again') | ||
|
|
||
| } | ||
|
|
||
| // Unit Tests | ||
| // You use them run the command: npm test main.js | ||
| // to close them ctrl + C | ||
| if (typeof describe === 'function') { | ||
|
|
||
| // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built return the expected output. | ||
| describe('#rockPaperScissors()', () => { | ||
| it('should detect a tie', () => { | ||
| assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!"); | ||
| assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!"); | ||
| assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!"); | ||
| }); | ||
| it('should detect which hand won', () => { | ||
| assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!"); | ||
| }); | ||
| it('should scrub input to ensure lowercase with "trim"ed whitepace', () => { | ||
| assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); | ||
| }); | ||
| }); | ||
| } else { | ||
|
|
||
| // always returns ask the user for another input | ||
| getPrompt(); | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
these are not all the cases.