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
36 changes: 33 additions & 3 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ const rl = readline.createInterface({


function pigLatin(word) {

// Your code here

// make (word) all lowercase
const lowerThatCase = word.toLowerCase().trim();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice daisy chain.

// make that into array
const splitWord = lowerThatCase.split('');
// check if any vowels if not move on to normalcy
if (splitWord[0] === 'a' || splitWord[0] === 'e' || splitWord[0] === 'i' || splitWord[0] === 'o' || splitWord[0] === 'u'){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using what you now know about .indexOf(), this could be simplified.

return lowerThatCase + 'yay';
} else {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else statement runs after the first letter is determined to not be a vowell, but then assumes the next letter is.

const firstLetter = splitWord.shift();
const removeFirstLetter = splitWord.join('');
return removeFirstLetter + firstLetter + 'ay';
}
}

pigLatin('ALEX');


function getPrompt() {
rl.question('word ', (answer) => {
Expand Down Expand Up @@ -49,3 +60,22 @@ if (typeof describe === 'function') {
getPrompt();

}


// Global Storage, what do I need to keep on the largest scope
// None I can think of maybe using a variable = 'ay'?

//Break the string into an array, method to use
// const stringToArray , using word.split(',')

// Save the first value in the array, method to use
// Using a const firstLetter = stringToArray[0]

// Remove the first letter, method to use
// const removeFirstLetter = using stringToArray.shift() as the method

//Name of function, turning the array back into a string, method to use
// const removeFirstLetter using .join()

//Function to join the variable to the rest of the string and add "ay"
// Return the var of + removeFirstLetter + "ay"