diff --git a/index.html b/index.html index 16517707..7b8ed08f 100644 --- a/index.html +++ b/index.html @@ -2,18 +2,22 @@ - - + Pig Latin +

Hello World!


-
-
+ + -
+
+
+ + + diff --git a/main-dom.js b/main-dom.js new file mode 100644 index 00000000..c7e5e38f --- /dev/null +++ b/main-dom.js @@ -0,0 +1,46 @@ +'use strict'; + + +const pigLatin = () => { + //get the value from the html form input + let word = document.getElementById("user-input").value; + + let inputWord = word.trim().toLowerCase(); + + let vowels = ['a', 'e', 'i', 'o', 'u']; + + for (let i = 0; i< inputWord.length; i++) { + // word starts with a vowel, + if(vowels.includes(inputWord[0])) { + let newWord = inputWord + "yay" + + // return the newWord to the DOM, directly inside display-element div + + document.getElementById('display-element').innerHTML = newWord + + // return to the console + // return newWord; + } else if + (!vowels.includes(inputWord[0]) && + !vowels.includes(inputWord[1]) + ) { + // word starts with one consonant + // remove the first letter, put it at the end, add ay + + let newWord = inputWord.slice(2) + inputWord.slice(0,2) + "ay" + document.getElementById('display-element').innerHTML = newWord + + // return newWord + + } else { + let newWord = inputWord.slice(1) + inputWord.slice(0,1) + "ay" + document.getElementById('display-element').innerHTML = newWord + + // return newWord + + } + } + + +} + diff --git a/main.js b/main.js index 282f4c93..42b57811 100644 --- a/main.js +++ b/main.js @@ -10,10 +10,49 @@ const rl = readline.createInterface({ output: process.stdout }); - const pigLatin = (word) => { // Your code here + let inputWord = word.trim().toLowerCase(); + let vowels = ['a', 'e', 'i', 'o', 'u']; + + for (let i = 0; i< inputWord.length; i++) { + // word starts with a vowel, + if(vowels.includes(inputWord[0])) { + let newWord = inputWord + "yay" + return newWord; + } else if (!vowels.includes(inputWord[0]) && !vowels.includes(inputWord[1])) { + // word starts with one consonant + // remove the first letter, put it at the end, add ay + + let newWord = inputWord.slice(2) + inputWord.slice(0,2) + "ay" + return newWord + + } else { + let newWord = inputWord.slice(1) + inputWord.slice(0,1) + "ay" + return newWord + + } + } + + /** takes a word (string) as an input +* makes input lowercase and trim +* +* +* +*FOR LOOP TO CHECK: +* if word starts with consonant, remove 1st letter, move it to end, add ay +* if word starts with 2 consonants, remove 1st 2 letters, put them at end, add ay +* if word starts with a vowel, add yay +* +* Start: +* ==> Need array variable to hold consonant or vowels +* ==> Less vowels to check, so start here. +* Assumptions: +* vowels are a e i o u +* +* +*/ } diff --git a/package.json b/package.json index 3afb478f..b9a1e1ad 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,9 @@ "mocha": "^5.0.0", "postcss-html": "^0.34.0", "stylelint": "^7.13.0" - } + }, + "main": "main.js", + "devDependencies": {}, + "keywords": [], + "license": "ISC" } diff --git a/style.css b/style.css new file mode 100644 index 00000000..e69de29b