Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM LAB #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions newStats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function callFunctionHere() {

let input = Number(document.getElementById('number-statistics-number-input').value)

let li = document.createElement('li')
let ul = document.getElementById('number-statistics-number-ul')
li.textContent = input

ul.appendChild(li)

console.log(ul.children)

let allItems = document.querySelectorAll('#number-statistics-numbers-li')

for (let i = 0; i < allItems.length; i++) {
console.log(allItems[i].textContent)
}



}
37 changes: 37 additions & 0 deletions numStats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
let sum = 0
let min = Infinity
let max = -Infinity
let counter = 0

function numberStats() {
const input = document.querySelector('#number-statistics-number-input')
const value = input.value

const num = Number(value)
const li = document.createElement('li')
li.textContent = num
const list = document.querySelector('#number-statistics-numbers')
list.appendChild(li)

let avg = 0
sum += num
counter++
avg = Math.floor(sum / counter)

if(num < min) {
min = num
}

if(num > max) {
max = num
}

const pAvg = document.querySelector('#number-statistics-average')
pAvg.textContent = `Average of all numbers is: ${avg}`

const pMax = document.querySelector('#number-statistics-maximum')
pMax.textContent = `Maximum of all numbers is: ${max}`

const pMin = document.querySelector('#number-statistics-minimum')
pMin.textContent = `Minimum of all numbers is: ${min}`
}
11 changes: 10 additions & 1 deletion numberStatistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>Number Statistics</title>
<script src="numStats.js" defer></script>
</head>
<body>
<h1>Number Statistics</h1>
Expand All @@ -21,8 +22,16 @@ <h1>Number Statistics</h1>
<li>
The first paragraph should show the average of all the numbers,
the second paragraph should show the maximum value,
and the third paragraph should show the minimum value.
and the third paragraph should show the minimum value.
</li>
</ul>
<input id="number-statistics-number-input" type="number" placeholder="Enter a number">
<ul id="number-statistics-numbers"></ul>

<p id="number-statistics-average"></p>
<p id="number-statistics-maximum"></p>
<p id="number-statistics-minimum"></p>

<button id="number-statistics-button" onclick="numberStats()">Submit</button>
</body>
</html>
Loading