Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="it">
- <head>
- <meta charset="UTF-8">
- <title>3.2.10 Es 6</title>
- </head>
- <body>
- <table style="border: 1px solid lightgray">
- <tr><th>Nome</th><th>Età</th></tr>
- <script>
- function confrontaStringhe( a, b ) {
- if ( a.nome < b.nome ){return -1;}
- if ( a.nome > b.nome ){return 1;}
- return 0;
- }
- let arr=[];let dato; let media=0;
- do {
- dato={};
- dato.nome=prompt("inserisci nome");
- let e=prompt("inserisci età");
- dato.eta=parseInt(e);
- //document.getElementById("demo").innerHTML ="Input: " + dato.eta ;
- arr.push(dato);
- } while (dato.nome!="");
- arr.pop();
- console.log(arr);
- arr.sort(confrontaStringhe);
- console.log(arr);
- for (let i = 0; i < arr.length; i++) {
- document.write("<tr></tr><td>"+arr[i].nome+"</td><td>"+arr[i].eta+"</td></tr>");
- media += arr[i].eta;
- }
- media=media/arr.length;
- document.write("</table><p>Media: "+media+"</p>");
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement