diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..e69de29b diff --git a/dom-main.js b/dom-main.js new file mode 100644 index 00000000..00bfe707 --- /dev/null +++ b/dom-main.js @@ -0,0 +1,43 @@ +let value = ""; + +const storeString = (valA) => { + value = valA; +}; + +// const displayTranslation = (translatedWord) => { +// var newDiv = document.createElement("P"); +// newDiv.innerText = (translatedWord); +// document.body.appendChild(newDiv); +// } + +const displayTranslation = (translatedWord) => { + var newDiv = document.createElement("P"); + newDiv.innerText = translatedWord; + newDiv.id = "pigLatinResult"; + document.body.appendChild(newDiv); + + //replace previous word upon new button click + let previousWord = document.getElementById("pigLatinResult"); + let parentDiv = previousWord.parentNode; + parentDiv.replaceChild(newDiv, previousWord); +}; + +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); + } +}; + +// console.log(pigLatin('Alabama')) diff --git a/index.html b/index.html index 8f536de8..698378cf 100644 --- a/index.html +++ b/index.html @@ -1,15 +1,56 @@ - - - - - - -

Hello World!

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

Pig Latin-ator

+
Pig Latin is not actually a language but a language game used to speak “in code.” Pig Latin + words are formed by altering + words in English.
+
+
+ +
+ +
+
+ + + + + \ No newline at end of file diff --git a/main.js b/main.js index 1c92f304..beb00e12 100644 --- a/main.js +++ b/main.js @@ -11,15 +11,45 @@ const rl = readline.createInterface({ }); + 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 { + // we used a regex BOOM + let firstMatch = cleanWord.match(/[aeiou]/g) || 0; + let vowelIndex = cleanWord.indexOf(firstMatch[0]); + finalWord = cleanWord.substring(vowelIndex) + cleanWord.substring(0, vowelIndex) + "ay"; + return finalWord; + } +} + +console.log(pigLatin('Alabama')) + + + +// if word begins with consonant +// list the vowels: a, e, i, o, u ** +// run through string until we find the first vowel +// identify index position, store and use +// store sound before vowel in a variable (bucket) + +// splice out 'y' (first sound) +// concat/push 'y' (first sound) to end + +// concat 'ay' to the end - // Your code here -} // the first function called in the program to get an input from the user // to run the function use the command: node main.js // to close it ctrl + C + + const getPrompt = () => { rl.question('word ', (answer) => { console.log( pigLatin(answer) ); diff --git a/package.json b/package.json index 3afb478f..66aebab9 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "jsdom": "^11.6.2", "mocha": "^5.0.0", "postcss-html": "^0.34.0", - "stylelint": "^7.13.0" + "stylelint": "^7.13.0", + "tailwindcss": "^2.0.2" } }