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
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
<head>
<meta charset="utf-8">
<title></title>
<script src="main.js"></script>
<script src="index.js" defer></script>
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<div id="display-element"></div>

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

</form>
<hr/>
</body>
Expand Down
31 changes: 31 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const userInput = document.getElementById("user-input")
const output = document.getElementById("display-element")
const translateWord = (event) => {
event.preventDefault()
// console.log(userInput.value)
const newWord = pigLatin(userInput.value)
output.innerText = newWord
console.log(newWord)
}


const pigLatin = (word) => {

// Your code here
let text = word.trim().toLowerCase()
const vowels = ["a","e","i","o","u"]
let newWord
if (vowels.includes(text[0])){
newWord = text + "yay"
}
else {
for (let i = 0; i < text.length; i++){
if (vowels.includes(text[i])) {
newWord = text.slice(i) + text.slice(0,i) + "ay"
break
}
}
}

return newWord
}
17 changes: 16 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@ const rl = readline.createInterface({
const pigLatin = (word) => {

// Your code here
let text = word.trim().toLowerCase()
const vowels = ["a","e","i","o","u"]
let newWord
if (vowels.includes(text[0])){
newWord = text + "yay"
}
else {
for (let i = 0; i < text.length; i++){
if (vowels.includes(text[i])) {
newWord = text.slice(i) + text.slice(0,i) + "ay"
break
}
}
}

return newWord
}

// the first function called in the program to get an input from the user
Expand All @@ -26,7 +41,7 @@ const getPrompt = () => {
getPrompt();
});
}

pigLatin("cat");
// Unit Tests
// to use them run the command: npm test main.js
// to close them ctrl + C
Expand Down