I'm trying to make a code that will evaluate numbers in a list from user input and will calculate the sum, average, minimum, and maximum of that list. I have already gotten the sum part from help from others. I can't seem to find how to get the maximum and minimum numbers from the list. Im trying to have all of the functions (sum, average, max, and min) as buttons just like the sum button that is already in the code and when clicked on it will alert the user of that specific function.
.title { font-weight:bold; margin-top:1em; }
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<!--- This only allows the user to input numbers --->
<input type='number' id='input'>
<!--- This is the button that adds the number to the list --->
<input type='button' value='add to list' id='add' disabled="disabled">
<!--- This will list all of the numbers in the list --->
<div class="title">Topics</div>
<ul id='list'></ul>
<!--- When clicked, this will alert the user with the sum of their numbers --->
<button id="something">Click Here To See The Sum</button>
<script>
let list = document.getElementById("list");;
let btn = document.getElementById("something");
let input = document.getElementById("input");
let add = document.getElementById("add");
var sum = 0;
input.addEventListener("input", enableDisable);
btn.addEventListener("click", sumvar);
add.addEventListener("click", function() {
var li = document.createElement("li");
li.textContent = input.value;
sum += +input.value;
list.appendChild(li);
input.value = "";
add.disabled = "disabled";
});
// This allows the "add to list" button to be turned on/off depending if the user has typed in a number
function enableDisable(){
if(this.value === ""){
add.disabled = "disabled";
} else {
add.removeAttribute("disabled");
}
}
// This function will alert the user of the sum of their numbers
function sumvar() {
alert("The sum of your numbers is: " + sum);
}
</script>
</body>
</html>