From 5979351c0f7e4d6151cdb8984b989eee4d5609d3 Mon Sep 17 00:00:00 2001 From: capatterson1970 Date: Mon, 29 Jun 2020 21:02:42 -0500 Subject: [PATCH 1/3] First finished push --- main.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 1c92f304..6c5f23c9 100644 --- a/main.js +++ b/main.js @@ -14,7 +14,31 @@ const rl = readline.createInterface({ const pigLatin = (word) => { // Your code here - + let vowel1 = 0; + let found = false; + word = word.trim().toLowerCase(); + let wordArr = word.split(''); + + //console.log(word[0]); + + if(word[0] === 'a' || word[0] === 'e' || word[0] === 'i' || word[0] === 'o' || word[0] === 'u') { + console.log(word+"yay"); + return word +"yay"; + } + + else { + for(let i = 1; i < wordArr.length; i++){ + + if((wordArr[i] === 'a' || wordArr[i] === 'e' || wordArr[i] === 'i' || wordArr[i] === 'o' || wordArr[i] === 'u') && (!found)){ + vowel1 = i; + found = true; + } + } + + console.log(word.slice(vowel1) + word.slice(0, vowel1) + "ay"); + return word.substring(vowel1) + word.substring(0, vowel1) + "ay"; + + } } // the first function called in the program to get an input from the user From f999bc5e5eab7bd8eb7e2f2def5a57abc07f8bbf Mon Sep 17 00:00:00 2001 From: capatterson1970 Date: Thu, 9 Jul 2020 20:39:13 -0500 Subject: [PATCH 2/3] Pre-changes made for GUI --- index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 8f536de8..84444e05 100644 --- a/index.html +++ b/index.html @@ -2,14 +2,14 @@ - + Pig Latin -

Hello World!

-
-
- -
+

Pig Latin Converter

+

Engter your word to be translated into Pig Latin

+ + + From 63bbd850679343f14701608fbd87f993b5ae8db0 Mon Sep 17 00:00:00 2001 From: capatterson1970 Date: Sun, 12 Jul 2020 19:25:07 -0500 Subject: [PATCH 3/3] GUI Upload --- index.html | 11 +++++--- main.js | 76 +++++++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/index.html b/index.html index 84444e05..58330efe 100644 --- a/index.html +++ b/index.html @@ -3,13 +3,16 @@ Pig Latin - +

Pig Latin Converter

Engter your word to be translated into Pig Latin

- - - +

+ + +
+ +

diff --git a/main.js b/main.js index 6c5f23c9..378e1d55 100644 --- a/main.js +++ b/main.js @@ -1,19 +1,20 @@ 'use strict'; // brings in the assert module for unit testing -const assert = require('assert'); +//const assert = require('assert'); // brings in the readline module to access the command line -const readline = require('readline'); +//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 rl = readline.createInterface({ +// input: process.stdin, +// output: process.stdout +// }); const pigLatin = (word) => { // Your code here + // let word = document.getElementById("word").value; let vowel1 = 0; let found = false; word = word.trim().toLowerCase(); @@ -23,6 +24,7 @@ const pigLatin = (word) => { if(word[0] === 'a' || word[0] === 'e' || word[0] === 'i' || word[0] === 'o' || word[0] === 'u') { console.log(word+"yay"); + document.getElementById("pigLat").innerHTML = word+"yay"; return word +"yay"; } @@ -36,6 +38,7 @@ const pigLatin = (word) => { } console.log(word.slice(vowel1) + word.slice(0, vowel1) + "ay"); + document.getElementById("pigLat").innerHTML = word.slice(vowel1) + word.slice(0, vowel1) + "ay"; return word.substring(vowel1) + word.substring(0, vowel1) + "ay"; } @@ -44,41 +47,44 @@ const pigLatin = (word) => { // 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(); - }); + let answer = document.getElementById("word").value; + pigLatin(answer); + // 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(); - -} +// 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(); + +// }