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
26 changes: 26 additions & 0 deletions dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

const storeString = (valA) => {
value = valA
}

const displayTranslation = (translatedWord) => {
// document.getElementById("results").innerHTML = translatedWord
document.createElement('results')
// let newElement = document.createElement("P");
// newElement.appendChild(translatedWord);
}

const pigLatin = () => {
let vowels = ['a', 'e', 'i', 'o', 'u'];
let finalWord = "";
let cleanWord = value.toLowerCase().trim()
if (vowels.indexOf(cleanWord[0]) > -1) {
finalWord = cleanWord + "yay";
return displayTranslation(finalWord)
} else {
let firstMatch = cleanWord.match(/[aeiou]/g) || 0;
let vowelIndex = cleanWord.indexOf(firstMatch[0]);
finalWord = cleanWord.substring(vowelIndex) + cleanWord.substring(0, vowelIndex) + "ay";
return displayTranslation(finalWord)
}
}
28 changes: 15 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="main.js"></script>
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<div id="display-element"></div>
<button onclick="displayDate()">Click Me</button>
<hr/>
</body>
</html>
<head>
<meta charset="utf-8">
<title>Pig Latin</title>
</head>
<body>
<h1>Let's do Pig Latin Stuff!</h1>
<hr/>
<div id="display-element"></div>
<input type="text" id="stringInput" value="" placeholder="Type a word!" oninput="storeString(this.value)"></input>
<button onclick="pigLatin()">get piggy!</button>
<div id="results"></div>
<hr/>
<script src="dom.js"></script>
</body>
</html>
22 changes: 20 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,29 @@ const rl = readline.createInterface({
});


const pigLatin = (word) => {

const pigLatin = (word) => {
let vowels = ["a", "e", "i", "o", "u"];
let finalWord = "";
// scrub the data
let cleanWord = word.toLowerCase().trim();
// if word begins with vowel add 'yay'
if (vowels.indexOf(cleanWord[0]) > -1) {
finalWord = cleanWord + "yay";
// Your code here

return finalWord;
}
// if word begins with consonant
else {
// run through string until we find the first vowel. What match() does is it returns an array of all the character indexes that match our regular expression pattern. Our pattern looks at any character that is a vowel. If there are no vowels, then we assign firstMatch the value of 0.
let firstMatch = cleanWord.match(/[aeiou]/g) || 0;
// index of the first vowel found in the string using indexOf()
let vowelIndex = cleanWord.indexOf(firstMatch[0]);
//string without the consonant beginning + the consonant + ay
finalWord = cleanWord.substring(vowelIndex) + cleanWord.substring(0, vowelIndex) + "ay";
return finalWord;
}
};

// the first function called in the program to get an input from the user
// to run the function use the command: node main.js
Expand Down