diff --git a/dom.js b/dom.js new file mode 100644 index 00000000..1b5cd6b6 --- /dev/null +++ b/dom.js @@ -0,0 +1,26 @@ + +const storeString = (valA) => { + value = valA + } + + const displayTranslation = (translatedWord) => { + // document.getElementById("results").innerHTML = translatedWord + document.createElement('results') + // let newElement = document.createElement("P"); + // newElement.appendChild(translatedWord); + } + + const pigLatin = () => { + let vowels = ['a', 'e', 'i', 'o', 'u']; + let finalWord = ""; + let cleanWord = value.toLowerCase().trim() + if (vowels.indexOf(cleanWord[0]) > -1) { + finalWord = cleanWord + "yay"; + return displayTranslation(finalWord) + } else { + let firstMatch = cleanWord.match(/[aeiou]/g) || 0; + let vowelIndex = cleanWord.indexOf(firstMatch[0]); + finalWord = cleanWord.substring(vowelIndex) + cleanWord.substring(0, vowelIndex) + "ay"; + return displayTranslation(finalWord) + } + } \ No newline at end of file diff --git a/index.html b/index.html index 8f536de8..30318673 100644 --- a/index.html +++ b/index.html @@ -1,15 +1,17 @@ - - - - - - -

Hello World!

-
-
- -
- - + + +Pig Latin + + +

Let's do Pig Latin Stuff!

+
+
+ + +
+
+ + + \ No newline at end of file diff --git a/main.js b/main.js index 1c92f304..509ce139 100644 --- a/main.js +++ b/main.js @@ -11,11 +11,29 @@ const rl = readline.createInterface({ }); -const pigLatin = (word) => { +const pigLatin = (word) => { + 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"; // Your code here - + 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; } +}; // the first function called in the program to get an input from the user // to run the function use the command: node main.js