-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
58 lines (44 loc) · 1.5 KB
/
index.html
File metadata and controls
58 lines (44 loc) · 1.5 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<html>
<ul id="list"></ul>
<label>Enter another link </label><input type="text" id="userinput">
<button id="button">submit</button>
<label>Enter the name of link </label><input type="text" id="userinput2">
<button id="button2">submit</button>
<script>
var nameLinks, links;
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
}
}
// Describe this function...
function itemdisplay() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
while (!!links.length) {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
let element_list = document.getElementById('list');
let new_li = document.createElement('li');
let new_a = document.createElement('a');
new_a.setAttribute("href", links.shift());
new_a.innerText = nameLinks.shift();
new_li.appendChild(new_a);
element_list.appendChild(new_li);
}
}
nameLinks = ['Manchester United', 'BBC', 'SkyNews'];
links = ['https://www.manutd.com/', 'https://www.bbc.co.uk/', 'https://news.sky.com/'];
itemdisplay();
document.getElementById('button').addEventListener('click', (event) => {
links.push(getNumberOrString(document.getElementById('userinput').value));
itemdisplay();
});
document.getElementById('button2').addEventListener('click', (event) => {
nameLinks.push(getNumberOrString(document.getElementById('userinput2').value));
itemdisplay();
});
</script>
</html>