ASDV-WebDev/Semester 1/Assignments/JavaScript/lab17js_CalebFontenot/public_html/index.html

49 lines
2.1 KiB
HTML

2023-04-12 17:37:37 +07:00
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<label id="numArray"></label><br>
<label id="averageLabel"></label><br>
<label id="arraySquare"></label><br>
<label id="stdDevLabel"></label><br>
<label id="numCountLabel"></label><br>
<label id="sumLabel"></label>
</body>
<script>
var numberArray = [];
do {
var userInput = prompt("Please enter a number. Type q/Q to quit.");
if (userInput.toLowerCase() != "q" && userInput != "") {
numberArray.push(parseInt(userInput));
console.log(numberArray);
}
} while (userInput.toLowerCase() != "q");
//Let's calculate stuff!
let average, arraySum = 0, arraySquare = 0, stdDev = 0;
for (let i = 0; i < numberArray.length; ++i) {
arraySum += numberArray[i]; // sum
}
average = arraySum / numberArray.length; // Average
for (let i = 0; i < numberArray.length; ++i) {
arraySquare += Math.pow(numberArray[i] - average, 2);
}
stdDev = Math.sqrt(arraySquare, (numberArray - 1));
document.getElementById("numArray").innerHTML = "Number Array: " + numberArray;
document.getElementById("averageLabel").innerHTML = "Average: " + average;
document.getElementById("arraySquare").innerHTML = "Square of elements in array: " + arraySquare;
document.getElementById("stdDevLabel").innerHTML = "Standard Deviation: " + stdDev;
document.getElementById("numCountLabel").innerHTML = "Number of Elements in array: " + numberArray.length;
document.getElementById("sumLabel").innerHTML = "Sum of elements in array: " + arraySum;
</script>
</html>