From 05eb3dba2a20b7e0641c376f25b265a57e583c5f Mon Sep 17 00:00:00 2001 From: Apple Date: Sun, 7 Jun 2020 22:25:47 -0500 Subject: [PATCH] initial commit piglatin --- .vscode/settings.json | 3 ++ main.js | 98 +++++++++++++++---------------------------- 2 files changed, 36 insertions(+), 65 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6f3a2913 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/main.js b/main.js index 1c92f304..37f09b04 100644 --- a/main.js +++ b/main.js @@ -1,71 +1,39 @@ '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 - + +let newword = prompt() +let vowels ="iuoae"; +for(let i =0; i< vowels.length; i ++){ +// will translate the any word starting with a vowel + let letter = newword[i]; + let answer = vowels.includes(letter); + if(i == 0 && answer == true){ + console.log(newword + "yay") + } +// will translate dog and car + if( i==0&& answer == false){ + let firsthalf = newword.substring(0,1) + let secondhalf = newword.substring(1,3) +if(firsthalf == firsthalf && secondhalf == secondhalf){ + console.log((secondhalf + firsthalf + "ay") ) + + } +// will translate create + if(i==0&& answer == false){ + let firsthalf = newword.substring(0,2) + let secondhalf = newword.substring(2,6) + if(firsthalf == firsthalf && secondhalf == secondhalf){ + console.log(secondhalf + firsthalf + "ay") + } +// will translate valley,hello and rocket +if(i==0&& answer == false){ + let firsthalf = newword.substring(0,1) + let secondhalf = newword.substring(1,6) + if(firsthalf == firsthalf && secondhalf == secondhalf){ + console.log(secondhalf + firsthalf + "ay") + } } -// 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(); - +} } - - - - - - -// ********** -// 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