Duvida de um iniciante #2098
Unanswered
AlefPr
asked this question in
Perguntas e Respostas
Replies: 2 comments
-
Espero que ajude. Segue um exemplo:
const alunos = converterAlunosHTMLParaJson()
let resultadoHTML = '<table border="1">'
let i = 0
while (i < alunos.length) {
const media = (Number(alunos[i]['1AV']) + Number(alunos[i]['2AV'])) / 2
const cabecalhoTabela = '<th>Nome</th><th>Média</th><th>Situação</th>'
const alunoTabela = `<td>${alunos[i].Nome}</td><td>${media}</td>${media >= 6 ? '<td class="ok">Aprovado</td>' : '<td class="nOK">Recuperação</td>'}`
resultadoHTML += `${i === 0 ? `<tr>${cabecalhoTabela}</tr><tr>${alunoTabela}</tr>` : `<tr>${alunoTabela}</tr>`}`
i++;
}
resultadoHTML += "</table>" Solução Completa<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8" />
<title>Situação dos Alunos</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 40%;
}
td,
th {
border: 2px solid #dddddd;
padding: 8px;
}
th {
text-align: center;
}
td:not(:first-child) {
text-align: right;
}
.ok {
color: green;
}
.nOK {
color: red;
}
.ok::after {
content: "🎉";
}
.nOK::after {
content: "🔥";
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h2>Lista dos Alunos</h2>
<table border="1">
<tr>
<th>Nome</th>
<th>1AV</th>
<th>2AV</th>
</tr>
<tr>
<td>Fulano de tal</td>
<td>3.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Beltrano da Silva</td>
<td>7.5</td>
<td>5.5</td>
</tr>
<tr>
<td>Zé Ninguém</td>
<td>8.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Fulano de tal</td>
<td>3.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Beltrano da Silva</td>
<td>7.5</td>
<td>5.5</td>
</tr>
<tr>
<td>Zé Ninguém</td>
<td>8.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Fulano de tal</td>
<td>3.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Beltrano da Silva</td>
<td>7.5</td>
<td>5.5</td>
</tr>
<tr>
<td>Zé Ninguém</td>
<td>8.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Fulano de tal</td>
<td>3.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Beltrano da Silva</td>
<td>7.5</td>
<td>5.5</td>
</tr>
<tr>
<td>Zé Ninguém</td>
<td>8.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Fulano de tal</td>
<td>3.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Beltrano da Silva</td>
<td>7.5</td>
<td>5.5</td>
</tr>
<tr>
<td>Zé Ninguém</td>
<td>8.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Fulano de tal</td>
<td>3.5</td>
<td>6.5</td>
</tr>
<tr>
<td>Beltrano da Silva</td>
<td>7.5</td>
<td>5.5</td>
</tr>
<tr>
<td>Zé Ninguém</td>
<td>8.5</td>
<td>6.5</td>
</tr>
</table>
<h2>Situação dos Alunos</h2>
<div id="resultado"></div>
<script>
const alunos = converterAlunosHTMLParaJson()
let resultadoHTML = '<table border="1">'
let i = 0
while (i < alunos.length) {
const media = (Number(alunos[i]['1AV']) + Number(alunos[i]['2AV'])) / 2
const cabecalhoTabela = '<th>Nome</th><th>Média</th><th>Situação</th>'
const alunoTabela = `<td>${alunos[i].Nome}</td><td>${media}</td>${media >= 6 ? '<td class="ok">Aprovado</td>' : '<td class="nOK">Recuperação</td>'}`
resultadoHTML += `${i === 0 ? `<tr>${cabecalhoTabela}</tr><tr>${alunoTabela}</tr>` : `<tr>${alunoTabela}</tr>`}`
i++;
}
resultadoHTML += "</table>"
document.getElementById("resultado").innerHTML = resultadoHTML
// Função para converter a tabela com a lista de alunos em um array de objetos aluno
function converterAlunosHTMLParaJson() {
const cabecalhoHTML = [...document.querySelectorAll('th')].map(({ textContent }) => textContent)
const alunosHTML = [...document.querySelectorAll('tr:not(:first-child)')]
return alunosHTML.map(linha => (
{
...[...linha.querySelectorAll('td')].reduce((aluno, { textContent }, i) => (
{
...aluno,
[cabecalhoHTML[i]]: textContent
}
), {})
}
))
}
</script>
</body>
</html> |
Beta Was this translation helpful? Give feedback.
0 replies
-
E qual a sua dúvida? O que vc fez até agora? Posta pra gente que a gente explica e tenta chegar numa solução. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Olá, boa tarde, sei que pode parecer algo bem simples para alguns, mas estou tendo algumas dificuldades com essa questão, eu consigo obter a até o resultado de sua média mas não consigo sair disso, alguém poderia só mostrar um sentido para que eu siga.
essa é questão, utilizando a Estrutura de Repetição "Enquanto"
cada aluno, o seu nome, a sua média e a sua situação (aprovado ou recuperação)
a média para aprovação é de 6
Beta Was this translation helpful? Give feedback.
All reactions