From d39e9fb6cf90f3939d9661535a410d69307560c2 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Wed, 15 Jul 2020 18:57:54 -0500 Subject: [PATCH 1/9] YAY --- main.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/main.js b/main.js index 1c92f304..071cb892 100644 --- a/main.js +++ b/main.js @@ -11,12 +11,71 @@ const rl = readline.createInterface({ }); -const pigLatin = (word) => { - // Your code here + + +// ********** +// HINTS +// ********** + +// 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. + + +// "yesTerday" => esterdayyay +// scrub the data +// if word begins with vowel add 'yay' +// turn our string into an array + + +// 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 + +let vowelArray = ['a', 'e', 'i', 'o', 'u'] + + + + +const findWord = () => { } + +const pigLatin = (word) => { + let splitWord = word.trim().toLowerCase().split('') + let yay = "yay" + const addYay = () => { + return word.concat(yay) + } + for(let i = 0; i < splitWord.length; i++) { + if (vowelArray.includes(splitWord)) { + addYay(); + } else { + findWord(); + } + } + + return addYay() + +} + + + + + + // 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 @@ -57,15 +116,3 @@ if (typeof describe === 'function') { } - - - - -// ********** -// HINTS -// ********** - -// 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. \ No newline at end of file From 4a310cad8cd6f51ff517d2761099db9cc72a5c08 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 03:04:10 -0500 Subject: [PATCH 2/9] semi-breakthrough --- main.js | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/main.js b/main.js index 071cb892..d9577820 100644 --- a/main.js +++ b/main.js @@ -23,53 +23,46 @@ const rl = readline.createInterface({ // 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. - // "yesTerday" => esterdayyay -// scrub the data -// if word begins with vowel add 'yay' -// turn our string into an array // 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 -let vowelArray = ['a', 'e', 'i', 'o', 'u'] - - - - -const findWord = () => { - -} - - const pigLatin = (word) => { - let splitWord = word.trim().toLowerCase().split('') - let yay = "yay" - const addYay = () => { - return word.concat(yay) + let splitWord = word.trim().toLowerCase().split('') + const vowelArray = ['a', 'e', 'i', 'o', 'u'] + for(let i = 0; i < splitWord.length; i++) { + if (vowelArray.includes(splitWord[0])) { + return word.concat("yay"); + } else { + findFirstVowel(); + } + } } - for(let i = 0; i < splitWord.length; i++) { - if (vowelArray.includes(splitWord)) { - addYay(); - } else { - findWord(); + + const findFirstVowel = (firstVowel) => { + for(let i = 0; i < splitWord.length; i++) { + if (splitWord[i].includes(vowelArray)) { + return splitWord.search(vowelArray) + } else { + + } } + } return addYay() -} + + From 3c81a2edd1684257f35d251301eb79b5d9f3f92d Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 04:11:35 -0500 Subject: [PATCH 3/9] let it be --- main.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/main.js b/main.js index d9577820..75ca1e9f 100644 --- a/main.js +++ b/main.js @@ -36,30 +36,38 @@ const rl = readline.createInterface({ // concat 'ay' to the end + +const vowelArray = ['a', 'e', 'i', 'o', 'u'] + const pigLatin = (word) => { let splitWord = word.trim().toLowerCase().split('') - const vowelArray = ['a', 'e', 'i', 'o', 'u'] - for(let i = 0; i < splitWord.length; i++) { - if (vowelArray.includes(splitWord[0])) { - return word.concat("yay"); - } else { - findFirstVowel(); - } - } + for(let i = 0; i < splitWord.length; i++) { + if (vowelArray.includes(splitWord[0])) { + return word.concat("yay"); + } else { + return findFirstVowel(splitWord); + } } + + +} - const findFirstVowel = (firstVowel) => { - for(let i = 0; i < splitWord.length; i++) { - if (splitWord[i].includes(vowelArray)) { - return splitWord.search(vowelArray) - } else { +const findFirstVowel = (consonantWord) => { + let foundVowel = + for(let i = 0; i < vowelArray.length; i++) { + if (splitWord.includes(vowelArray[i])) { + return splitWord.search(vowelArray.join()); + // modifyWord() - } + // } + // else { + + // } } } +} - return addYay() From 4321e8d1bdc51c463e3fc443a6dd2b7dc5ea13a0 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 04:13:04 -0500 Subject: [PATCH 4/9] turn-in commit --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 75ca1e9f..1fbeab05 100644 --- a/main.js +++ b/main.js @@ -34,7 +34,7 @@ const rl = readline.createInterface({ // splice out 'y' (first sound) // concat/push 'y' (first sound) to end -// concat 'ay' to the end +// concat 'ay' to the end const vowelArray = ['a', 'e', 'i', 'o', 'u'] From 1263c4577ca72b85625de3b7698ddc678e32b10a Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 05:08:36 -0500 Subject: [PATCH 5/9] this seems significant --- main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 1fbeab05..a6335420 100644 --- a/main.js +++ b/main.js @@ -53,10 +53,11 @@ const pigLatin = (word) => { } const findFirstVowel = (consonantWord) => { - let foundVowel = + let poop = consonantWord.join() for(let i = 0; i < vowelArray.length; i++) { - if (splitWord.includes(vowelArray[i])) { - return splitWord.search(vowelArray.join()); + if (poop.includes(vowelArray[i])) { + return poop.search(vowelArray.join()); + // modifyWord() // } From 0224351b2d5953e930ce8a6b652df28321945199 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 05:15:57 -0500 Subject: [PATCH 6/9] black magic is afoot --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index a6335420..72c5a581 100644 --- a/main.js +++ b/main.js @@ -56,7 +56,7 @@ const findFirstVowel = (consonantWord) => { let poop = consonantWord.join() for(let i = 0; i < vowelArray.length; i++) { if (poop.includes(vowelArray[i])) { - return poop.search(vowelArray.join()); + return poop.match(vowelArray[i]); // modifyWord() From a6cf0afe197413771a1e4960c9b5411a8fb08126 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 19 Jul 2020 23:52:35 -0500 Subject: [PATCH 7/9] damn destiny and ariel... that's some fine code... --- main.js | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/main.js b/main.js index 72c5a581..4c87017d 100644 --- a/main.js +++ b/main.js @@ -37,37 +37,23 @@ const rl = readline.createInterface({ // concat 'ay' to the end -const vowelArray = ['a', 'e', 'i', 'o', 'u'] - -const pigLatin = (word) => { - let splitWord = word.trim().toLowerCase().split('') - for(let i = 0; i < splitWord.length; i++) { - if (vowelArray.includes(splitWord[0])) { - return word.concat("yay"); - } else { - return findFirstVowel(splitWord); - } +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.slice(vowelIndex) + cleanWord.slice(0, vowelIndex) + "ay"; + return finalWord; } - - } - -const findFirstVowel = (consonantWord) => { - let poop = consonantWord.join() - for(let i = 0; i < vowelArray.length; i++) { - if (poop.includes(vowelArray[i])) { - return poop.match(vowelArray[i]); - - // modifyWord() - // } - // else { - // } - } - - } -} From 2ff8b4d172c5b10f5c43f19eb467782bd138353f Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Mon, 20 Jul 2020 03:19:13 -0500 Subject: [PATCH 8/9] i may not have wrote it, but i stared at it for like 5 hrs --- main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 4c87017d..a589d3ce 100644 --- a/main.js +++ b/main.js @@ -42,10 +42,9 @@ const pigLatin = (word) => { let finalWord = ""; let cleanWord = word.toLowerCase().trim() if (vowels.indexOf(cleanWord[0]) > -1) { - finalWord = cleanWord + "yay"; - return finalWord; + 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.slice(vowelIndex) + cleanWord.slice(0, vowelIndex) + "ay"; From 9fc8b33253b775ac32d8e61c07c1ce09f4fab030 Mon Sep 17 00:00:00 2001 From: michaelscoggins Date: Sun, 26 Jul 2020 05:42:31 -0500 Subject: [PATCH 9/9] finally --- index.html | 9 +--- main.js | 112 ++++++++---------------------------------------- terminal app.js | 105 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 101 deletions(-) create mode 100644 terminal app.js diff --git a/index.html b/index.html index 8f536de8..46ab1829 100644 --- a/index.html +++ b/index.html @@ -3,13 +3,8 @@ - + - -

Hello World!

-
-
- -
+ diff --git a/main.js b/main.js index a589d3ce..98a1545f 100644 --- a/main.js +++ b/main.js @@ -1,105 +1,29 @@ -'use strict'; -// brings in the assert module for unit testing -const assert = require('assert'); -// brings in the readline module to access the command line -const readline = require('readline'); -// use the readline module to print out to the command line -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - - - - - -// ********** -// HINTS -// ********** - -// 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. - -// "yesTerday" => esterdayyay - - -// if word begins with consonant -// 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 - - -const pigLatin = (word) => { +//created elements +let translationText = document.createElement("H2") +translationText.innerText = ("Pig Latin Translator") +let translateButton = document.createElement("BUTTON") +let textInput = document.createElement("INPUT") +document.body.appendChild(translationText) +document.body.appendChild(textInput) +document.body.appendChild(translateButton) +translateButton.innerText = "Translate" +// inject h2 with pigLatin result +const displayPigLatin = (translatedWord => translationText.innerHTML = translatedWord) +//run pigLatin +const pigLatin = () => { let vowels = ['a', 'e', 'i', 'o', 'u']; let finalWord = ""; - let cleanWord = word.toLowerCase().trim() + let cleanWord = textInput.value.toLowerCase().trim(); if (vowels.indexOf(cleanWord[0]) > -1) { finalWord = cleanWord + "yay"; - return finalWord; + return displayPigLatin(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; + return displayPigLatin(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 -// to close it ctrl + C -const getPrompt = () => { - rl.question('word ', (answer) => { - console.log( pigLatin(answer) ); - getPrompt(); - }); -} - -// Unit Tests -// You use them run the command: npm test main.js -// to close them ctrl + C -if (typeof describe === 'function') { - - describe('#pigLatin()', () => { - it('should translate a simple word', () => { - assert.equal(pigLatin('car'), 'arcay'); - assert.equal(pigLatin('dog'), 'ogday'); - }); - it('should translate a complex word', () => { - assert.equal(pigLatin('create'), 'eatecray'); - assert.equal(pigLatin('valley'), 'alleyvay'); - }); - it('should attach "yay" if word begins with vowel', () => { - assert.equal(pigLatin('egg'), 'eggyay'); - assert.equal(pigLatin('emission'), 'emissionyay'); - }); - it('should lowercase and trim word before translation', () => { - assert.equal(pigLatin('HeLlO '), 'ellohay'); - assert.equal(pigLatin(' RoCkEt'), 'ocketray'); - }); - }); -} else { - - getPrompt(); - -} - - +//invoke with click +translateButton.addEventListener('click', pigLatin) \ No newline at end of file diff --git a/terminal app.js b/terminal app.js new file mode 100644 index 00000000..a589d3ce --- /dev/null +++ b/terminal app.js @@ -0,0 +1,105 @@ +'use strict'; + +// brings in the assert module for unit testing +const assert = require('assert'); +// brings in the readline module to access the command line +const readline = require('readline'); +// use the readline module to print out to the command line +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + + + + + +// ********** +// HINTS +// ********** + +// 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. + +// "yesTerday" => esterdayyay + + +// if word begins with consonant +// 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 + + +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; + } +} + + + + + + + + + + + + +// 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) ); + getPrompt(); + }); +} + +// Unit Tests +// You use them run the command: npm test main.js +// to close them ctrl + C +if (typeof describe === 'function') { + + describe('#pigLatin()', () => { + it('should translate a simple word', () => { + assert.equal(pigLatin('car'), 'arcay'); + assert.equal(pigLatin('dog'), 'ogday'); + }); + it('should translate a complex word', () => { + assert.equal(pigLatin('create'), 'eatecray'); + assert.equal(pigLatin('valley'), 'alleyvay'); + }); + it('should attach "yay" if word begins with vowel', () => { + assert.equal(pigLatin('egg'), 'eggyay'); + assert.equal(pigLatin('emission'), 'emissionyay'); + }); + it('should lowercase and trim word before translation', () => { + assert.equal(pigLatin('HeLlO '), 'ellohay'); + assert.equal(pigLatin(' RoCkEt'), 'ocketray'); + }); + }); +} else { + + getPrompt(); + +} + +