generated from AustinCodingAcademy/JS211_CurrentDateTimeProject
-
Notifications
You must be signed in to change notification settings - Fork 227
initial commit piglatin #4
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:mybranch
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "liveServer.settings.port": 5501 | ||
| } |
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,71 +1,39 @@ | ||
| '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 | ||
| }); | ||
|
|
||
|
|
||
| const pigLatin = (word) => { | ||
|
|
||
| // Your code here | ||
|
|
||
|
|
||
| let newword = prompt() | ||
| let vowels ="iuoae"; | ||
| for(let i =0; i< vowels.length; i ++){ | ||
| // will translate the any word starting with a vowel | ||
| let letter = newword[i]; | ||
| let answer = vowels.includes(letter); | ||
| if(i == 0 && answer == true){ | ||
| console.log(newword + "yay") | ||
| } | ||
| // will translate dog and car | ||
| if( i==0&& answer == false){ | ||
| let firsthalf = newword.substring(0,1) | ||
| let secondhalf = newword.substring(1,3) | ||
| if(firsthalf == firsthalf && secondhalf == secondhalf){ | ||
| console.log((secondhalf + firsthalf + "ay") ) | ||
|
|
||
| } | ||
| // will translate create | ||
| if(i==0&& answer == false){ | ||
| let firsthalf = newword.substring(0,2) | ||
| let secondhalf = newword.substring(2,6) | ||
| if(firsthalf == firsthalf && secondhalf == secondhalf){ | ||
| console.log(secondhalf + firsthalf + "ay") | ||
| } | ||
| // will translate valley,hello and rocket | ||
| if(i==0&& answer == false){ | ||
| let firsthalf = newword.substring(0,1) | ||
| let secondhalf = newword.substring(1,6) | ||
| if(firsthalf == firsthalf && secondhalf == secondhalf){ | ||
| console.log(secondhalf + firsthalf + "ay") | ||
| } | ||
| } | ||
|
|
||
| // 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 | ||
| const getPrompt = () => { | ||
| rl.question('word ', (answer) => { | ||
| console.log( pigLatin(answer) ); | ||
| getPrompt(); | ||
| }); | ||
| } | ||
|
|
||
| // Unit Tests | ||
| // You use them run the command: npm test main.js | ||
| // to close them ctrl + C | ||
| if (typeof describe === 'function') { | ||
|
|
||
| describe('#pigLatin()', () => { | ||
| it('should translate a simple word', () => { | ||
| assert.equal(pigLatin('car'), 'arcay'); | ||
| assert.equal(pigLatin('dog'), 'ogday'); | ||
| }); | ||
| it('should translate a complex word', () => { | ||
| assert.equal(pigLatin('create'), 'eatecray'); | ||
| assert.equal(pigLatin('valley'), 'alleyvay'); | ||
| }); | ||
| it('should attach "yay" if word begins with vowel', () => { | ||
| assert.equal(pigLatin('egg'), 'eggyay'); | ||
| assert.equal(pigLatin('emission'), 'emissionyay'); | ||
| }); | ||
| it('should lowercase and trim word before translation', () => { | ||
| assert.equal(pigLatin('HeLlO '), 'ellohay'); | ||
| assert.equal(pigLatin(' RoCkEt'), 'ocketray'); | ||
| }); | ||
| }); | ||
| } else { | ||
|
|
||
| getPrompt(); | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // ********** | ||
| // HINTS | ||
| // ********** | ||
|
|
||
| // break your code into pieces and focus on one piece at a time... | ||
| // 1. if word begins with a vowel send to one function: adds "yay" | ||
| // 2. if word begins in with a consonant send to another function: splices off beginning, returns word with new ending. | ||
| // 3. if multiple words, create array of words, loop over them, sending them to different functions and creating a new array with the new words. | ||
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.
you are really close, and heading in the right direction but this logic is still a bit off.