Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,28 @@ const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
/* I need at least two more functions to meet the benchmarks for this assignment. I will probably complete this and then find out there's a bunch of bugs and a way easier way, but leggo. */
/*Based on the tests, I need at least three functions. One of which will probably be specifically to address the vowel test. Would probably be best to use an if statement to look for vowels at the beginning of my chosen word, or in this case, a bunch of string. IF the word matches the criteria, then I will have it return the word+way. */
/* For any other words, it seems intuitive just to use a function that moves the first letter to the end of the word (maybe using an array method?) and then adding ay.*/
/* The first function below splits the word or string into an array of substrings, which allows the following functions to move letters (which now make up the new array) around. */
/* It seems like maybe a good idea to establish string as a global variable so it can be used for all functions without having to re-write it for each function*/

function splitWordIntoArray(word) {
return word.split('')
}

function pigLatin(word) {

// Your code here

const vowelArray = ["a", "e", "i", "o", "u"]
if (vowelArray.includes(word[0])) {
console.log("firstIsVowel")
return word+"way";
}else {
console.log("firstNotVowel")
const chars = splitWordIntoArray(word)
return chars.slice(1).join('') + chars[0] + 'ay';
}
}


function getPrompt() {
rl.question('word ', (answer) => {
console.log( pigLatin(answer) );
Expand Down