-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (22 loc) · 898 Bytes
/
index.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
const postRequest = require('./helper/util.js');
const clickHandler = document.querySelector('.clickHandler');
const outputField = document.querySelector('input[name=response]');
const inputString = document.querySelector('input[name=request]');
const updateInputField = () => {
postRequest(inputString.value).then(res => {
outputField.value = res.body;
inputString.value = '';
});
};
const changeDisplayMsg = () => {
clickHandler.textContent = 'Enter anything!!';
};
const changeDisplayMsgBack = () => {
clickHandler.textContent = 'I will sort your string!';
};
clickHandler.addEventListener('mouseenter', () => changeDisplayMsg());
clickHandler.addEventListener('mouseleave', () => changeDisplayMsgBack());
clickHandler.addEventListener('click', () => updateInputField());
document.addEventListener('keypress', event => {
if (event.key == 'Enter') updateInputField();
});