forked from danielscarvalho/FTT-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaulajs13.html
More file actions
74 lines (52 loc) · 2.21 KB
/
Copy pathaulajs13.html
File metadata and controls
74 lines (52 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Aula 13</title>
<script>
function getNumberList(quantidade) {
let numeros = [];
for (i=0; i < quantidade; i++) {
numeros.push(Math.random() * 100);
} //for
return numeros;
}
function getMean(numList) {
let sum = 0;
for(i=0; i<numList.length; i++) {
sum += numList[i];
} //for
return sum / numList.length;
}
function gerarNumeros() {
limpaItens();
var n = getNumberList(parseInt(document.getElementById("inputNumber").value));
var m = getMean(n);
//console.log(n);
//console.log(m);
document.getElementById("mediaInfo").innerHTML = m;
var lista = document.getElementById("numerosInfo");
n.forEach(function(val) { //função anonima
var li = document.createElement("li");
li.innerHTML = "Valor " + val;
lista.appendChild(li);
});
}
function limpaItens() {
document.getElementById("numerosInfo").innerHTML = '';
document.getElementById("mediaInfo").innerHTML = '';
}
</script>
</head>
<body>
<h1>JavaScript Aula 13</h1>
<h2>for, Math.random()</h2>
<button onclick="gerarNumeros();">Gerar números</button>
<button onclick="limpaItens();">Limpa Itens</button>
<hr>
<p><label>Quantidade de números: </label><input id="inputNumber" type="number" value="10" required> </input></p>
<p id="mediaInfo" style="width: 50%; background-color: lightgoldenrodyellow">
</p>
<ol id="numerosInfo" style="width: 50%; background-color: lightpink">
</ol>
</body>
</html>