-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: gh-pages
Are you sure you want to change the base?
Piglatin #4
Changes from all commits
ec218c4
d2ddbf2
581860b
539fc65
dc4cfda
8ad19f6
33b8b43
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 |
|---|---|---|
|
|
@@ -7,13 +7,82 @@ const rl = readline.createInterface({ | |
| output: process.stdout | ||
| }); | ||
|
|
||
| //planning | ||
| //input text | ||
| //check to see if valid (make sure string, check if any numbers), if not ask to re enter a word. checkValid() | ||
| //check for uppercase, turn all to lowercase. fixCase() | ||
| //check to see if start with vowel, if vowel, add yay to end. checkVowel() return it back | ||
| //turn entered word to array(splice). turnIntoList() | ||
| //go through array until first vowel(loop until vowel). checkConsonent() | ||
| //take letters until first vowel and put to the end (pop) and add ay. addVowelAy() | ||
|
|
||
| function pigLatin(word) { | ||
| var wordArray = turnToList(word); | ||
| if (checkValid(wordArray)) { | ||
| if (checkVowel(wordArray)) { | ||
| return wordArray.join("") + "yay"; | ||
| } else { | ||
| var vowelIndex = checkConsonant(wordArray); | ||
| pushConsonant(wordArray, vowelIndex); | ||
| return wordArray.join("") + "ay"; | ||
| } //end of checkVowel() | ||
| } else { | ||
| return "Please remove any numbers and try again" | ||
| } //end of checkValid() | ||
| } | ||
|
|
||
| const turnToList = (word) => { | ||
| const lowerCase = word.toLowerCase(); | ||
| const trimmed = lowerCase.trim(); | ||
| const toList = trimmed.split(""); | ||
| return toList; | ||
| } | ||
|
|
||
| // Your code here | ||
| const checkValid = (word) => { | ||
| const arrayLength = word.length; | ||
| for (var i = 0; i < arrayLength; i++) { | ||
| if (isNaN(word[i])) { | ||
|
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. just return the evaluation |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const checkVowel = (word) => { | ||
| const vowel = ["a", "e", "i", "o", "u"]; | ||
| for (var i = 0; i < vowel.length; i++) { | ||
| if (word[0] == vowel[i]) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| const checkConsonant = (word) => { | ||
|
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. why do you need a check for constant and vowel? |
||
| const vowel = ["a", "e", "i", "o", "u"]; | ||
| var i = 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 be let |
||
| var found = false; | ||
|
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 be let |
||
| while (!found && i < word.length) { | ||
| for (var j = 0; j < vowel.length; j++) { | ||
| if (word[i] == vowel[j]) { | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!found) { | ||
| i++; | ||
| } | ||
| } | ||
| return i; | ||
| } | ||
|
|
||
| const pushConsonant = (word, firstVowelIndex) => { | ||
| for (var i = 0; i < firstVowelIndex; i++) { | ||
| const letter = word.shift(); | ||
| word.push(letter); | ||
| } | ||
| } | ||
|
|
||
| function getPrompt() { | ||
| rl.question('word ', (answer) => { | ||
|
|
||
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.
don't use var, should be const