-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise24.html
46 lines (37 loc) · 1.42 KB
/
Exercise24.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Exercise 24</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript">
/*
Modificar el programa KC_EJ23 para que muestre los resultados ordenados por la media, de forma descendente.
*/
let number = 1;
let name;
let peoples = new Array();
while(true) {
name = prompt(`${number}) Agrega el nombre de una persona ('terminar' para finalizar)`);
if (name.toLowerCase() === 'terminar') {
break;
}
let average = 0;
for(let i = 1; i <= 4; i++) {
average += parseInt(prompt(`${number}) Ingresa la nota ${i}/4 de ${name}`));
}
average = average / 4;
peoples.push({'name': name, 'average': average});
number++;
}
let peoplesSorted = peoples.sort((a, b) => b.average - a.average);
for(let i = 0; i < peoplesSorted.length; i++) {
document.write(`${peoplesSorted[i].name} ${peoplesSorted[i].average}</br>`);
}
</script>
</body>
</html>