Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt-PT">
  3.  
  4. <head>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Laboratório 3</title>
  9. <link rel="stylesheet" type="text/css" href="./css/estilo.css">
  10. </head>
  11.  
  12. <body>
  13. <script type="text/javascript">
  14. var alunos = [["António", "Luísa", "Raquel", "Carlos", "Alexandre", "Cristina", "Nuno", "Manuel"], [12, 14, 8, 9, 18, 5, 12, 2]]
  15. document.write('<div>')
  16. document.write('<table>');
  17. document.write('<caption>Notas dos alunos</caption>')
  18. document.write('<tr><th>Nome</th><th>Nota</th><th>Resultado</th></tr>');
  19. for (i = 0; i < alunos[1].length; i++) {
  20. if (alunos[1][i] < 8) {
  21. document.write('<tr><td>' + alunos[0][i] + '</td><td>' + alunos[1][i] + '</td><td id=corVermelha>' + resultado(alunos[1][i]) + '</td></tr>');
  22. }
  23. else if (8 >= alunos[1][i] || alunos[1][i] < 9.5) {
  24. document.write('<tr><td>' + alunos[0][i] + '</td><td>' + alunos[1][i] + '</td><td id=corAmarela>' + resultado(alunos[1][i]) + '</td></tr>');
  25. }
  26. else if (9.5 >= alunos[1][i] || alunos[1][i] <= 20) {
  27. document.write('<tr><td>' + alunos[0][i] + '</td><td>' + alunos[1][i] + '</td><td id=corVerde>' + resultado(alunos[1][i]) + '</td></tr>');
  28. }
  29. }
  30. document.write('</table>');
  31. document.write('<p>A média das notas da turma é ' + media() + ' valores.</p>');
  32. document.write('<p>A maior nota da turma é ' + maiorNota() + ' valores que pertence ao aluno ' + alunoMaiorNota() + '.</p>');
  33. document.write('<p>A menor nota da turma é ' + menorNota() + ' valores que pertence ao aluno ' + alunoMenorNota() + '.</p>');
  34. document.write('<p>A nota da turma que mais aparace é ' + moda() + '.</p>');
  35. document.write('</div>')
  36. function resultado(nota) {
  37. var situacao = "";
  38. if (nota < 8) {
  39. situacao = "Reprovado";
  40. return situacao;
  41. }
  42. else if (8 >= nota || nota < 9.5) {
  43. situacao = "Prova Oral";
  44. return situacao;
  45. }
  46. else if (9.5 >= nota || nota <= 20) {
  47. situacao = "Aprovado";
  48. return situacao;
  49. }
  50. }
  51. function media() {
  52. var total = 0;
  53. for (i = 0; i < alunos[1].length; i++) {
  54. total += alunos[1][i];
  55. var media = 0;
  56. media = total / alunos[1].length;
  57. }
  58. return media;
  59. }
  60. function maiorNota() {
  61. var maior = 0;
  62. for (var i = 0; i < alunos[1].length; i++) {
  63. if (alunos[1][i] > maior) {
  64. maior = alunos[1][i];
  65. }
  66. }
  67. return maior;
  68. }
  69. function alunoMaiorNota() {
  70. var maior = 0;
  71. var alunoMaior = "";
  72. for (var i = 0; i < alunos[1].length; i++) {
  73. if (alunos[1][i] > maior) {
  74. maior = alunos[1][i];
  75. alunoMaior = alunos[0][i];
  76. }
  77. }
  78. return alunoMaior;
  79. }
  80. function menorNota() {
  81. var menor = Math.min.apply(Math, alunos[1]);
  82. return menor;
  83. }
  84.  
  85. function alunoMenorNota() {
  86. var menor = Number.MAX_VALUE;
  87. var alunoMaior = "";
  88. for (var i = 0; i < alunos[1].length; i++) {
  89. if (alunos[1][i] < menor) {
  90. menor = alunos[1][i];
  91. alunoMenor = alunos[0][i];
  92. }
  93. }
  94. return alunoMenor;
  95. }
  96. function moda() {
  97. var maior = null;
  98. var ocorrenciasMaior = -1;
  99. for (var i = 0; i < alunos[1].length; i++) {
  100. var ocorrencias = 1;
  101. for (var t = i + 1; t < alunos[1].length; t++)
  102. if (alunos[1][i] == alunos[1][t])
  103. ocorrencias++;
  104. if (ocorrencias > ocorrenciasMaior) {
  105. maior = alunos[1][i];
  106. ocorrenciasMaior = ocorrencias;
  107. }
  108. }
  109. return maior;
  110. }
  111. </script>
  112. </body>
  113.  
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement