Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ <h1>Hello World!</h1>
<hr/>
<div id="display-element"></div>
<button onclick="displayDate()">Click Me</button>
<input type="text" value="" id="pig-latin" onkeyup="pigLatin(this.id, this.value)">
<hr/>
</body>
</html>
44 changes: 42 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,48 @@ const rl = readline.createInterface({
output: process.stdout
});

let word = ""


const pigLatin = (word) => {
// list the vowels: a, e, i, o, u
let vowels = ["a", "e", "i", "o", "u"];
let finalWord = "";
// scrub the data
let cleanWord = word.toLowerCase().trim();
// if word begins with vowel add 'yay'
if (vowels.indexOf(cleanWord[0]) > -1) {
finalWord = cleanWord + "yay";
return finalWord;
}
// if word begins with consonant
else {
// run through string until we find the first vowel. What match() does is it returns an array of all the character indexes that match our regular expression pattern. Our pattern looks at any character that is a vowel. If there are no vowels, then we assign firstMatch the value of 0.
let firstMatch = cleanWord.match(/[aeiou]/g) || 0;
// index of the first vowel found in the string using indexOf()
let vowelIndex = cleanWord.indexOf(firstMatch[0]);
//string without the consonant beginning + the consonant + ay
finalWord = cleanWord.substring(vowelIndex) + cleanWord.substring(0, vowelIndex) + "ay";
return finalWord;
}
};


for (let i = 0; i < word.length; i++){
for(let i=1; i<item.length; i++){
if (item[i].match(vowel)){
return item.substring(i)+item.substring(0,i)+ '-ay';
}


}

// splice out 'y' (first sound)
// concat/push 'y' (first sound) to end


// concat 'ay' to the end

const pigLatin = (word) => {

// Your code here

Expand Down Expand Up @@ -68,4 +108,4 @@ if (typeof describe === 'function') {
// 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.
// 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