diff --git a/gui.js b/gui.js new file mode 100644 index 00000000..7bf89fde --- /dev/null +++ b/gui.js @@ -0,0 +1,55 @@ +// create onload input + + + + +//created elements +let textInput = document.createElement("INPUT") +let translateButton = document.createElement("BUTTON") +let translationText = document.createElement("DIV") +// console.log(, button, div) + +document.body.appendChild(textInput); +document.body.appendChild(translateButton); +document.body.appendChild(translationText) + +translateButton.innerText = "Translate" + +//storing a value +const storeInput = (word) => { + textInput = word +} +let word = "" +// console.log(word) + + +textInput.addEventListener("input", storeInput) + +//run pigLatin +const pigLatin = () => { + let vowels = ['a', 'e', 'i', 'o', 'u']; + let finalWord = ""; + let cleanWord = word.toLowerCase().trim(); + + if (vowels.indexOf(cleanWord[0]) > -1) { + finalWord = cleanWord + "yay"; + return finalWord; + } else { + let firstMatch = cleanWord.match(/[aeiou]/g) || 0; + let vowelIndex = cleanWord.indexOf(firstMatch[0]); + finalWord = cleanWord.slice(vowelIndex) + cleanWord.slice(0, vowelIndex) + "ay"; + return finalWord; + } +} + +// console.log(textInput) +//invoke with click +translateButton.addEventListener('click', pigLatin) + +//display translations + const displayPigLatin = (finalWord) => { + let newDiv = document.createElement("P"); + newDiv.innerText = (finalWord); + document.appendChild(newDiv); + } + \ No newline at end of file diff --git a/index.html b/index.html index 8f536de8..4d17f148 100644 --- a/index.html +++ b/index.html @@ -3,13 +3,12 @@ - + -

Hello World!

-
-
- -
+

Pig Latin!

+ + + diff --git a/main.js b/main.js index 1c92f304..92395921 100644 --- a/main.js +++ b/main.js @@ -10,12 +10,39 @@ const rl = readline.createInterface({ output: process.stdout }); +let word = "" const pigLatin = (word) => { + let vowels = ['a', 'e', 'i', 'o', 'u']; + let finalWord = ""; + let cleanWord = word.toLowerCase().trim() + if (vowels.indexOf(cleanWord[0]) > -1) { + finalWord = cleanWord + "yay"; + return finalWord; + } else { + let firstMatch = cleanWord.match(/[aeiou]/g) || 0; + let vowelIndex = cleanWord.indexOf(firstMatch[0]); + finalWord = cleanWord.slice(vowelIndex) + cleanWord.slice(0, vowelIndex) + "ay"; + return finalWord; + } +} - // Your code here -} + +// for (let i = 0; i < word.length; i++){ +// for(let i=1; i