-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (22 loc) · 921 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
var textInput = document.querySelector('.text-input');
var processButton = document.querySelector('.process-btn');
var divOutput = document.querySelector('.output')
// https://api.funtranslations.com/translate/morse.json
var serverURL = "https://api.funtranslations.com/translate/minion.json"
var serverURL = 'https://api.funtranslations.com/translate/morse.json'
function constructURL(text){
return serverURL +"?"+"text="+text
}
function errorHandler(error){
console.log('error occured', error);
alert('error occured!')
}
function process(){
var textboxValue = textInput.value;
fetch(constructURL(textboxValue)).then(response => response.json()).then(json =>
divOutput.innerText = json.contents.translated)
.catch(errorHandler)
// divOutput.innerText = `${textboxValue}`;
// console.log(textboxValue);
}
processButton.addEventListener('click', process);