Это мой HTML, я беру элементы от пользователя и пытаюсь обновить в js.
Это мой файл скрипта
// Initializing the Stack Class
function Stack() {
this.dataStore = [];
this.top = 0;
this.push = push; // Inserting the element in Stack
this.pop = pop; //Removing the element in Stack
this.peek = peek;
this.clear = clear;
this.length = length;
}
// Adding an element in Stack
function push(element) {
this.dataStore[this.top++] = element;
}
function peek() {
return this.dataStore[this.top - 1];
}
// Removing an element from the given stack
function pop() {
return this.dataStore[-this.top];
}
function clear() {
this.top = 0;
}
function length() {
return this.top;
}
var s = new Stack();
function pushToStack(el){
s.push(el);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body> <!-- <div> <input type="text" id="stackName"> <button onclick="MakeStack()">Make a stack</button> </div> -->
<div>
<input type="text" id="elemet">
<button onclick="pushToStack(document.getElementById('elemet').value)">
Push an elemet
</button>
</div>
<div class="container"></div>
<script src="script.js"></script>
</body>
</html>
Я хочу, чтобы при нажатии на кнопку данные из текстового поля сохранялись в массиве как стек, а данные должны отображаться в контейнере как мой элементСтек.Спасибо за помощь.