-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
30 lines (22 loc) · 793 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
const inputText = document.querySelector('#input');
const btnTranslate = document.querySelector('.btn');
const output = document.querySelector('#output');
const url = "https://api.funtranslations.com/translate/navi.json"
function fetchTranslateApi(text) {
return url + '?' + 'text=' + text
}
function errorHandler(error) {
console.log('error occured', error);
alert('There is a problem with the server! Please try again later');
}
function clickShow() {
let inptxt = inputText.value;
fetch(fetchTranslateApi(inptxt))
.then(response => response.json())
.then(json => {
let translatedOutput = json.contents.translated
output.innerText = translatedOutput
})
.catch(errorHandler);
}
btnTranslate.addEventListener('click', clickShow);