-
-
-
-
+
diff --git a/main.js b/main.js
index 1c92f304..98a1545f 100644
--- a/main.js
+++ b/main.js
@@ -1,71 +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
-});
-
-
-const pigLatin = (word) => {
-
- // 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) );
- 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();
+//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 = textInput.value.toLowerCase().trim();
+ if (vowels.indexOf(cleanWord[0]) > -1) {
+ finalWord = cleanWord + "yay";
+ 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 displayPigLatin(finalWord);
+ }
}
-
-
-
-
-
-
-// **********
-// 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
+//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();
+
+}
+
+