jenya2802,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script>
document.addEventListener("DOMContentLoaded", function() {
var arr = JSON.parse(localStorage.getItem("avg")) || [];
function average(arr) {
return arr.length ? arr.reduce(function(a, b) {
return a + b
}) / arr.length : 0
}
function show() {
var avg = average(arr);
document.getElementById("res").textContent = avg.toFixed(2)
}
function addSaveNum() {
var num = parseInt(document.getElementById("num").value);
if (!num) return;
arr.push(num);
localStorage.setItem("avg", JSON.stringify(arr));
show()
}
document.getElementById("btn").addEventListener("click", addSaveNum);
show()
});
</script>
</head>
<body>
<div id="res"></div>
<input type="text" id="num">
<button id="btn">go</button>
</body>
</html>