Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added deleteinghtml.html
Empty file.
Empty file added deleting.js
Empty file.
21 changes: 13 additions & 8 deletions numberStatistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@
<html>
<head>
<title>Number Statistics</title>
<script src="numberStatistics.js" defer></script>
</head>
<body>
<h1>Number Statistics</h1>

<ul>
<li>
The user should be able to enter a number into a number input with
id='number-statistics-number-input'


</li>
<li>They should then be able to click a "submit" button with id='number-statistics-button'</li>
<br>
<li>
Clicking the submit button will add that number to a list with
id='number-statistics-numbers'. There should be three paragraphs on the
page: id='number-statistics-average', id='number-statistics-maximum',
and id='number-statistics-minimum'.
</li>
<li>
The first paragraph should show the average of all the numbers,
id='number-statistics-numbers'.There should be three paragraph on
the second paragraph should show the maximum value,
and the third paragraph should show the minimum value.
</li>
<br>
<p>Add a number: <input id='number-statistics-number-input' type='number' placeholder='Enter Number'></p>
<button id="number-statistics-button" onclick="numberStats()" type="submit">Submit!</button>
<p id="number-statistics-average">Average:</p>
<p id="number-statistics-maximum">Maximum:</p>
<p id="number-statistics-minimum">Minimum:</p>
<ul id="number-statistics-numbers"></ul>
</ul>
</body>
</ul>
</html>
29 changes: 29 additions & 0 deletions numberStatistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const numberStats = () => {
let sum = 0;
let min = Infinity;
let max = -Infinity;
let count = 0;
let tempMax = -Infinity;
let tempMin = Infinity;
let inputNumber = document.querySelector("#number-statistics-input").value;
let listElement = document.querySelector("#number-statistics-numbers");
let newList = document.createElement("li");
let avgPara = document.getElementById("number-statistics-average");
let maxPara = document.getElementById("number-statistics-maximum");
let minPara = document.getElementById("number-statistics-minimum");
listElement.appendChild(newList);
newList.textContent = inputNumber;
count++
sum+=Number(inputNumber);
avgPara.innerText = sum/count;
tempMax = Number(inputNumber);
tempMin = Number(inputNumber);
if (tempMax > max) {
max = tempMax;
}
if (tempMin < min) {
min = tempMin;
}
maxPara.innerText = max;
minPara.innerText = min;
};
Loading