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
14 changes: 9 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="main.js"></script>
<title>Pig Latin</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<div id="display-element"></div>
<form>
<!-- <form> -->

<input id="user-input" type="text">
<!-- How do you get this input sent to the pigLatin() function? -->
<button onclick="pigLatin()">Translate</button>
</form>
<!-- </form> -->
<hr/>
<div id="display-element"></div>


<script src="main-dom.js"></script>
</body>
</html>
46 changes: 46 additions & 0 deletions main-dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';


const pigLatin = () => {
//get the value from the html form input
let word = document.getElementById("user-input").value;

let inputWord = word.trim().toLowerCase();

let vowels = ['a', 'e', 'i', 'o', 'u'];

for (let i = 0; i< inputWord.length; i++) {
// word starts with a vowel,
if(vowels.includes(inputWord[0])) {
let newWord = inputWord + "yay"

// return the newWord to the DOM, directly inside display-element div

document.getElementById('display-element').innerHTML = newWord

// return to the console
// return newWord;
} else if
(!vowels.includes(inputWord[0]) &&
!vowels.includes(inputWord[1])
) {
// word starts with one consonant
// remove the first letter, put it at the end, add ay

let newWord = inputWord.slice(2) + inputWord.slice(0,2) + "ay"
document.getElementById('display-element').innerHTML = newWord

// return newWord

} else {
let newWord = inputWord.slice(1) + inputWord.slice(0,1) + "ay"
document.getElementById('display-element').innerHTML = newWord

// return newWord

}
}


}

41 changes: 40 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,49 @@ const rl = readline.createInterface({
output: process.stdout
});


const pigLatin = (word) => {

// Your code here
let inputWord = word.trim().toLowerCase();
let vowels = ['a', 'e', 'i', 'o', 'u'];

for (let i = 0; i< inputWord.length; i++) {
// word starts with a vowel,
if(vowels.includes(inputWord[0])) {
let newWord = inputWord + "yay"
return newWord;
} else if (!vowels.includes(inputWord[0]) && !vowels.includes(inputWord[1])) {
// word starts with one consonant
// remove the first letter, put it at the end, add ay

let newWord = inputWord.slice(2) + inputWord.slice(0,2) + "ay"
return newWord

} else {
let newWord = inputWord.slice(1) + inputWord.slice(0,1) + "ay"
return newWord

}
}

/** takes a word (string) as an input
* makes input lowercase and trim
*
*
*
*FOR LOOP TO CHECK:
* if word starts with consonant, remove 1st letter, move it to end, add ay
* if word starts with 2 consonants, remove 1st 2 letters, put them at end, add ay
* if word starts with a vowel, add yay
*
* Start:
* ==> Need array variable to hold consonant or vowels
* ==> Less vowels to check, so start here.
* Assumptions:
* vowels are a e i o u
*
*
*/

}

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
"mocha": "^5.0.0",
"postcss-html": "^0.34.0",
"stylelint": "^7.13.0"
}
},
"main": "main.js",
"devDependencies": {},
"keywords": [],
"license": "ISC"
}
Empty file added style.css
Empty file.