diff --git a/index.html b/index.html index 16517707..c320d850 100644 --- a/index.html +++ b/index.html @@ -2,17 +2,17 @@ - - + Pig Latin Translator + -

Hello World!

+

Translate any word to pig latin!


-
+ - +

diff --git a/main.js b/main.js index 282f4c93..c99896f0 100644 --- a/main.js +++ b/main.js @@ -1,60 +1,108 @@ -'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 +// }); + +// const form = document.getElementById("form") +// form.addEventListener("submit", (e) => { +// e.preventDefault() +// }) + +// const input = document.getElementById("user-input") +// input.addEventListener("input", (event) => { +// console.log(event.target.value) +// }) -// 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) => { +word = document.getElementById('user-input').value +word = word.toLowerCase().trim() +console.log("Your first letter is " + word [0]) -const pigLatin = (word) => { - // Your code here +let firstletter = word[0] +let vowels = ["a", "e", "i", "o", "u"] +let vowelPosition = 0 + +//If it starts with a vowel just add "yay" + +if(vowels.includes( firstletter ) == true) +{ + document.getElementById("display-element").innerHTML = word + "yay" + return word + "yay" +//it is a vowel +} + +else{ + + //not a vowel + + for (let index = 0; index < word.length; index = index + 1) { + + if(vowels.includes(word[index])){ + +vowelPosition = index + +break; + } +//check each letter to see how many consonants there are in a row + + } + + + let finalAnswer = word.slice(vowelPosition) + word.slice(0, vowelPosition) + "ay" + document.getElementById("display-element").innerHTML = finalAnswer + return finalAnswer + +} } // 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(); - }); -} +// 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(); + +// }