-3
I need to solve a seemingly simple exercise for a Javascript course, but I’m not getting it done.
I need to take the data from a form where I add the name, surname and age of a person, create a list of the people I add and after that, make an age comparison to show the user who is the oldest person.
I already managed to make the form and add people creating the list.. only this missing make age comparison and show who is the oldest person for the user.
In this link I left a video with my more explicit doubt for you to understand a little better, what I’m trying to solve. https://youtu.be/KP7rTY710NE
function adicionarPessoa() {
let nome = document.querySelector("#nome")
let sobreNome = document.querySelector("#sobreNome")
let idade = document.querySelector("#idade")
let lista = document.querySelector("#lista")
let registro = document.querySelector("#registro")
registro.textContent = "Registros de:"
let nomeCompleto = `${nome.value} ${sobreNome.value}: ${idade.value}`
nome.value = ""
sobreNome.value = ""
idade.value = ""
let pessoaRegistrada = document.createElement("li")
pessoaRegistrada.textContent = nomeCompleto
lista.appendChild(pessoaRegistrada)
}
document.querySelector("#botao").addEventListener("click", adicionarPessoa)
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>teste</title>
</head>
<body>
<form>
<label>
Nome:
<input id="nome" type="text" name="nome" />
</label>
<label>
Sobrenome:
<input id="sobreNome" type="text" name="SobreNome" />
</label>
<label>
Idade:
<input id="idade" type="number" name="idade" />
</label>
<button id="botao" type="button">Adicionar</button>
</form>
<p id="registro"></p>
<ul id="lista"></ul>
<p id="comparacao"></p>
<script src="script.js"></script>
</body>
</html>
go through the list picking up the age attribute and when you have been going through will have an if that will store the age in a variable only when the current age is greater than the one that is already stored
– Victor Pereira