Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
<head>
<meta charset="utf-8">
<title></title>
<script src="main.js"></script>

</head>
<body>
<h1>Hello World!</h1>
<h1>Pig Latin Translator </h1>
<hr/>
<div id="display-element"></div>
<form>
<input id="user-input" type="text">
<label id="user-input"></label><input type="text"/>
<!-- How do you get this input sent to the pigLatin() function? -->
<button onclick="pigLatin()">Translate</button>

<button type="button" onclick="pigLatin()">Translate</button>
<div id="results">
<h2></h2>
</div>
</form>
<hr/>
</body>
<script src="main.js"></script>
</html>
34 changes: 28 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
'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
});


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
Expand Down Expand Up @@ -61,6 +82,7 @@ if (typeof describe === 'function') {




// **********
// HINTS
// **********
Expand Down
42 changes: 42 additions & 0 deletions main2.js
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}