From 694b3de48c94a83aae4c2bc326822e563d053e2f Mon Sep 17 00:00:00 2001 From: brookecowey Date: Sun, 9 Apr 2023 18:38:59 -0500 Subject: [PATCH 1/2] updated js --- main.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 282f4c93..f71943a5 100644 --- a/main.js +++ b/main.js @@ -11,9 +11,46 @@ const rl = readline.createInterface({ }); + const pigLatin = (word) => { +word = word.toLowerCase().trim() + +console.log("Your first letter is " + word [0]) + + +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) +{ + return word + "yay" +//it is a vowel +} + +else{ + + //not a vowel - // Your code here + 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" + return finalAnswer + +} } From 4c9d383bc852e2be0e966f2e003db820c182d30b Mon Sep 17 00:00:00 2001 From: brookecowey Date: Sun, 16 Apr 2023 13:49:57 -0500 Subject: [PATCH 2/2] added GUI --- index.html | 10 +++--- main.js | 99 ++++++++++++++++++++++++++++++------------------------ 2 files changed, 60 insertions(+), 49 deletions(-) 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 f71943a5..c99896f0 100644 --- a/main.js +++ b/main.js @@ -1,18 +1,27 @@ -'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 -}); - - +// '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) +// }) const pigLatin = (word) => { +word = document.getElementById('user-input').value word = word.toLowerCase().trim() console.log("Your first letter is " + word [0]) @@ -26,6 +35,7 @@ let vowelPosition = 0 if(vowels.includes( firstletter ) == true) { + document.getElementById("display-element").innerHTML = word + "yay" return word + "yay" //it is a vowel } @@ -48,6 +58,7 @@ break; let finalAnswer = word.slice(vowelPosition) + word.slice(0, vowelPosition) + "ay" + document.getElementById("display-element").innerHTML = finalAnswer return finalAnswer } @@ -57,41 +68,41 @@ break; // 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(); + +// }