From 406898a2b751a02934aa728e86c6cafdb3bb131d Mon Sep 17 00:00:00 2001 From: omarusmani Date: Thu, 26 May 2022 07:41:32 -0500 Subject: [PATCH 1/2] made it as short as possible --- main.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.js b/main.js index 282f4c93..512d18aa 100644 --- a/main.js +++ b/main.js @@ -12,6 +12,24 @@ const rl = readline.createInterface({ const pigLatin = (word) => { + let vowels=["a","e","i","o","u"];// was going to user or's but switched to array method includes + let wrd=word.trim().toLowerCase(); + console.log(wrd) + if(vowels.includes(wrd[0])){ + return wrd+"yay" + } + else{ + for(let i=0;i Date: Thu, 26 May 2022 23:54:21 -0500 Subject: [PATCH 2/2] partial gui --- index.html | 3 +- main.js | 145 ++++++++++++++++++++++++++------------------------- package.json | 1 + 3 files changed, 78 insertions(+), 71 deletions(-) diff --git a/index.html b/index.html index 16517707..f55187c9 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ -

Hello World!

+

Pig Latin!


@@ -15,5 +15,6 @@

Hello World!


+

diff --git a/main.js b/main.js index 512d18aa..bcddcce4 100644 --- a/main.js +++ b/main.js @@ -1,30 +1,35 @@ -'use strict'; +// '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 -}); +// // 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) => { +const pigLatin = () => { + let input=document.getElementById("user-input").value; let vowels=["a","e","i","o","u"];// was going to user or's but switched to array method includes - let wrd=word.trim().toLowerCase(); - console.log(wrd) - if(vowels.includes(wrd[0])){ - return wrd+"yay" + // let wrd=word.trim().toLowerCase(); + let ipt=input.trim().toLowerCase(); + console.log(ipt) + if(vowels.includes(ipt[0])){ + console.log(ipt+"yay") + document.getElementById("output").innerHTML=ipt+"yay"; + return ipt+"yay" } else{ - for(let i=0;i { } -// 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. +// // 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. diff --git a/package.json b/package.json index 3afb478f..e014c785 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "jsdom": "^11.6.2", "mocha": "^5.0.0", "postcss-html": "^0.34.0", + "server": "^1.0.37", "stylelint": "^7.13.0" } }