From 147c886ba4212dc4fead567081832d7d0313a7b4 Mon Sep 17 00:00:00 2001 From: MarisolM09 Date: Sat, 16 Apr 2022 20:36:19 -0500 Subject: [PATCH 1/4] finished --- main.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 282f4c93..a34c2d51 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,6 @@ 'use strict'; +const { strictEqual } = require('assert'); // brings in the assert module for unit testing const assert = require('assert'); // brings in the readline module to access the command line @@ -11,12 +12,32 @@ const rl = readline.createInterface({ }); -const pigLatin = (word) => { +const pigLatin = (str) => { + str = str.trim('').toLowerCase(); + + let vowels = ["a", "e", "i", "o", "u"] + + if (vowels.indexOf(str[0]) > -1) { + return str = str + "yay"; + } + // words that start with one or more consonants + else { + for (let i = 0; i -1){ + let firstCons = str.slice(0, i); + let middle = str.slice(i, str.length); + str = middle + firstCons + "ay"; + break; + } + } + return str; + } +} + + // 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 From b85832a7d70d75bc1d7e29b972bb2cb45f273eec Mon Sep 17 00:00:00 2001 From: MarisolM09 Date: Sat, 16 Apr 2022 20:55:36 -0500 Subject: [PATCH 2/4] concat --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index a34c2d51..f4ae1888 100644 --- a/main.js +++ b/main.js @@ -26,7 +26,7 @@ const pigLatin = (str) => { if (vowels.indexOf(str[i]) > -1){ let firstCons = str.slice(0, i); let middle = str.slice(i, str.length); - str = middle + firstCons + "ay"; + str = middle.concat(firstCons) + "ay"; break; } } From 0d5dc2fd2cb50238b7345adf15b12a0ddb7fbf55 Mon Sep 17 00:00:00 2001 From: MarisolM09 Date: Mon, 25 Apr 2022 21:21:22 -0500 Subject: [PATCH 3/4] event listeners --- index.html | 9 +++++++-- main.js | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 16517707..416fadb7 100644 --- a/index.html +++ b/index.html @@ -3,10 +3,10 @@ - + -

Hello World!

+

Pig Latin


@@ -15,5 +15,10 @@

Hello World!


+
    + +
+ + diff --git a/main.js b/main.js index f4ae1888..9a604cbb 100644 --- a/main.js +++ b/main.js @@ -14,7 +14,7 @@ const rl = readline.createInterface({ const pigLatin = (str) => { str = str.trim('').toLowerCase(); - + let vowels = ["a", "e", "i", "o", "u"] if (vowels.indexOf(str[0]) > -1) { @@ -33,8 +33,19 @@ const pigLatin = (str) => { return str; } } - +let input = document.querySelector('#user-input').addEventListener('input', ); + +button.addEventListener("click", () => { + let ul = document.getElementById('Translated-PigLatinWord') + let li = document.createElement('li'); + li.appendChild(document.createTextNode()) + ul.appendChild(li) +}) + + + + // Your code here From bd885c751e9b660269f195a500475f7fc15f264b Mon Sep 17 00:00:00 2001 From: MarisolM09 Date: Wed, 27 Apr 2022 16:53:26 -0500 Subject: [PATCH 4/4] GUI --- index.html | 3 +- main.js | 150 +++++++++++++++++++++++++++-------------------------- 2 files changed, 79 insertions(+), 74 deletions(-) diff --git a/index.html b/index.html index 416fadb7..ba2fed99 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,8 @@

Pig Latin

- + +

    diff --git a/main.js b/main.js index 9a604cbb..b1a2deb4 100644 --- a/main.js +++ b/main.js @@ -1,18 +1,21 @@ -'use strict'; - -const { strictEqual } = require('assert'); -// 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 = (str) => { +// 'use strict'; + +// const { strictEqual } = require('assert'); +// // 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 = () => { + console.log() + let str = document.querySelector('#user-input').value; + str = str.trim('').toLowerCase(); let vowels = ["a", "e", "i", "o", "u"] @@ -30,74 +33,75 @@ const pigLatin = (str) => { break; } } - return str; - } -} - -let input = document.querySelector('#user-input').addEventListener('input', ); - -button.addEventListener("click", () => { + // return str; + } let ul = document.getElementById('Translated-PigLatinWord') let li = document.createElement('li'); - li.appendChild(document.createTextNode()) + li.appendChild(document.createTextNode(str)) ul.appendChild(li) -}) - - - - - - // 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 -// to 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(); -} + -// ********** -// HINTS -// ********** + + // Your code here -// 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 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. +// 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 +// // to 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(); + +// } + + + + + + +// // ********** +// // 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 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.