-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (33 loc) · 973 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { translateStringToMorse } from "./translator.js";
// selectors
let userInput = document.getElementById("user-input");
let output = document.getElementById("output");
const clearButton = document.getElementById("translate-button");
// functions
const refreshOutput = (toDisplayParam) => {
output.value = toDisplayParam;
return output.value;
};
const displayOutput = (translatedWordParam) => {
if (output.value === "There is no Output without an Input") {
output.value = "";
}
return (output.value += translatedWordParam);
};
// event listeners
clearButton.addEventListener("click", () => {
output.value = "";
userInput.value = "";
});
userInput.addEventListener("input", (event) => {
if (event.inputType === "deleteContentBackward") {
refreshOutput( translateStringToMorse(userInput.value) );
} else {
displayOutput( translateStringToMorse( event.data ) );
}
/*
try {
} catch (error) {
console.log(error);
} */
});