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/index.html b/index.html index 16517707..ed3592ec 100644 --- a/index.html +++ b/index.html @@ -3,17 +3,22 @@ - + -

Hello World!

+

Pig Latin Translator


- + - + + +
+

+

+ diff --git a/main.js b/main.js index 282f4c93..1190b17a 100644 --- a/main.js +++ b/main.js @@ -1,10 +1,10 @@ 'use strict'; -// brings in the assert module for unit testing +// // brings in the assert module for unit testing const assert = require('assert'); -// brings in the readline module to access the command line +// // 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 +// // use the readline module to print out to the command line const rl = readline.createInterface({ input: process.stdin, output: process.stdout @@ -12,19 +12,40 @@ const rl = readline.createInterface({ const pigLatin = (word) => { - // Your code here - + + word = word.toLowerCase(); + word = word.trim() + //vowels + const vowels = ["a", "e", "i", "o", "u"]; + let newWord = ''; +//if and else staments + return + 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 +// // 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 @@ -61,6 +82,7 @@ if (typeof describe === 'function') { + // ********** // HINTS // ********** 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. 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" } }