From 5d0a050339d91488855c28a3b8a514e9ebf25157 Mon Sep 17 00:00:00 2001 From: Jmirez2022 Date: Mon, 31 Oct 2022 10:02:23 -0500 Subject: [PATCH 1/3] finished --- README.md | 1 + main.js | 15 +++++++++++++-- package.json | 10 +++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f1054e0b..9af049ea 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ 1. Ensure you know how to run the unit test: * `npm test main.js` 1. Use a whiteboard to work out a solution to building the Pig Latin program +1. Use a whiteboard to work out a solution to building the Pig Latin program 1. Translate the broad ideas to pseudo code 1. Convert the pseudo code to real JavaScript Code 1. Type into your text editor the JavaScript code you've come up with one step at a time diff --git a/main.js b/main.js index 282f4c93..2566b05b 100644 --- a/main.js +++ b/main.js @@ -12,10 +12,21 @@ const rl = readline.createInterface({ const pigLatin = (word) => { - // Your code here - + word = word.toLowerCase().trim() + let vowels = ["a", "e", "i", "o", "u"]; + let newWord = '' + + if (vowels.includes(word[0])) { + return word + "yay"; + } else { + let arr = word.match(/[aeiou]/g) || 0; + let vIndex = word.indexOf(arr[0]); + newWord = word.slice(vIndex) + word.slice(0, vIndex) + 'ay'; + return newWord + } } +pigLatin("") // the first function called in the program to get an input from the user // to run the function use the command: node main.js diff --git a/package.json b/package.json index 3afb478f..261b7b2b 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,14 @@ }, "homepage": "https://github.com/AustinCodingAcademy/JS211_PigLatinProject#readme", "dependencies": { - "eslint": "^3.19.0", + "eslint": "^8.26.0", "functional-javascript-workshop": "^1.0.6", "htmllint-cli": "github:kevincolten/htmllint-cli", - "http-server": "^0.11.1", - "javascripting": "^2.6.1", - "jsdom": "^11.6.2", + "http-server": "^14.1.1", + "javascripting": "^2.4.0", + "jsdom": "^20.0.1", "mocha": "^5.0.0", "postcss-html": "^0.34.0", - "stylelint": "^7.13.0" + "stylelint": "^14.14.0" } } From dc03b46517af0eadeb6ba03a070a0d704025d659 Mon Sep 17 00:00:00 2001 From: Jmirez2022 Date: Tue, 8 Nov 2022 15:29:52 -0600 Subject: [PATCH 2/3] not finished --- index.html | 12 ++++-- main.js | 106 +++++++++++++++++++++++++++++++---------------------- main2.js | 42 +++++++++++++++++++++ 3 files changed, 112 insertions(+), 48 deletions(-) create mode 100644 main2.js diff --git a/index.html b/index.html index 16517707..12cb3a63 100644 --- a/index.html +++ b/index.html @@ -3,17 +3,21 @@ - -

Hello World!

+

Pig Latin Translator


- + - + + +
+

+

+ diff --git a/main.js b/main.js index 2566b05b..b9b4c5c7 100644 --- a/main.js +++ b/main.js @@ -1,21 +1,33 @@ '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 +// }); + +// // let input = ''; + +// let textInput = document.getElementById('text') +// console.log() + +// textInput.addEventListener('click', (event) => { +// console.log(event.target.value) +// }) + const pigLatin = (word) => { // Your code here - word = word.toLowerCase().trim() + word = word.toLowerCase(); + word = word.trim() + let vowels = ["a", "e", "i", "o", "u"]; - let newWord = '' + let newWord = ''; if (vowels.includes(word[0])) { return word + "yay"; @@ -25,47 +37,53 @@ const pigLatin = (word) => { newWord = word.slice(vIndex) + word.slice(0, vIndex) + 'ay'; return newWord } + } pigLatin("") + + + + // 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(); - }); -} +// // 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(); - -} +// 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(); + +// } diff --git a/main2.js b/main2.js new file mode 100644 index 00000000..ee41f516 --- /dev/null +++ b/main2.js @@ -0,0 +1,42 @@ + + + +const pigLatin = (word) => { + // Your code here + + word = word.toLowerCase().trim(); + const vowels = ["a", "e", "i", "o", "u"]; + let newWord = '' + + if (vowels.includes(word[0])) { + return word + "yay"; + } else { + let arr = word.match(/[aeiou]/g) || 0; + let vIndex = word.indexOf(arr[0]); + newWord = word.slice(vIndex) + word.slice(0, vIndex) + 'ay'; + return newWord + } +} +pigLatin("") + + + + + +// Unit Tests +// to use them run the command: npm test main.js + + + + + + + +// ********** +// 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. From 3103dbb35487634ad3523f00c5fcb74af88b8ff4 Mon Sep 17 00:00:00 2001 From: Jmirez2022 Date: Tue, 8 Nov 2022 23:29:32 -0600 Subject: [PATCH 3/3] best I can do --- index.html | 3 +- main.js | 95 +++++++++++++++++++++++++----------------------------- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/index.html b/index.html index 12cb3a63..ed3592ec 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ +

Pig Latin Translator

@@ -13,7 +14,7 @@

Pig Latin Translator

-
+

diff --git a/main.js b/main.js index b9b4c5c7..1190b17a 100644 --- a/main.js +++ b/main.js @@ -1,34 +1,25 @@ '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 -// }); - -// // let input = ''; - -// let textInput = document.getElementById('text') -// console.log() - -// textInput.addEventListener('click', (event) => { -// console.log(event.target.value) -// }) - +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); const pigLatin = (word) => { // Your code here + word = word.toLowerCase(); word = word.trim() - - let vowels = ["a", "e", "i", "o", "u"]; + //vowels + const vowels = ["a", "e", "i", "o", "u"]; let newWord = ''; - +//if and else staments + return if (vowels.includes(word[0])) { return word + "yay"; } else { @@ -39,6 +30,7 @@ const pigLatin = (word) => { } } + pigLatin("") @@ -47,43 +39,44 @@ pigLatin("") // 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(); -// }); +// 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(); - -// } +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(); + +} +