-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (20 loc) · 835 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
function getNumberOrString(value) {
// Convert a string value to a number if possible
let number_value = Number(value);
if (Number.isNaN(number_value)) {
return value
} else {
return number_value
}
}
let element_button = document.getElementById('button');
element_button.style.backgroundColor = '#000000';
element_button.style.color = '#ffffff';
document.getElementById('button').addEventListener('click', (event) => {
event.target.innerText = getNumberOrString(document.getElementById('comment').value);
let element_list = document.getElementById('list');
let new_li = document.createElement('li');
new_li.innerText = getNumberOrString(document.getElementById('comment').value);
new_li.style.color = '#000099';
element_list.appendChild(new_li);
});