-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathstack.html
44 lines (41 loc) · 838 Bytes
/
stack.html
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
<html>
<head>
<title>Stack in JavaScript</title>
<script>
let data = [];
let currentSize = data.length;
let max = 5;
function push(newVal) {
if (currentSize >= max) {
alert("Stack is full you can not add" + newVal);
}
data[currentSize] = newVal;
currentSize += 1;
}
function pop() {
if (currentSize > 0) {
currentSize -= 1;
data.length = currentSize;
} else {
alert("stack is already empty");
}
}
push(20);
push(30);
push(10);
push(2);
pop();
pop();
pop();
push(25);
push(23);
push(67);
// pop()
// pop()
console.warn(data);
</script>
</head>
<body>
<h1>Stack in JavaScript</h1>
</body>
</html>