-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical_3.html
More file actions
42 lines (37 loc) · 963 Bytes
/
Copy pathpractical_3.html
File metadata and controls
42 lines (37 loc) · 963 Bytes
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
#Madanraj Sagar
<!DOCTYPE html>
<html>
<head>
<title>Array Operations</title>
</head>
<body>
<button onclick="displayArray()">Display Array</button>
<button onclick="addNumber()">Add Number</button>
<button onclick="removeNumber()">Remove Number</button>
<button onclick="sortArray()">Sort Array</button>
<p id="arrayDisplay"></p>
<script>
let numbers = [1, 2, 3, 4, 5];
function displayArray() {
let display = "Array: ";
for (let i = 0; i < numbers.length; i++) {
display += numbers[i] + " ";
}
document.getElementById("arrayDisplay").textContent = display;
}
function addNumber() {
let numberToAdd = parseInt(prompt("Enter a number to add:"));
numbers.push(numberToAdd);
displayArray();
}
function removeNumber() {
numbers.pop();
displayArray();
}
function sortArray() {
numbers.sort();
displayArray();
}
</script>
</body>
</html>