-2
I am doing a programming exercise, my goal is to create a guest registration system based on arrays. At this time I am trying to implement a filter system to bar the registration according to a minimum age, I tried to do with the Array.filter
but I couldn’t, because I want an alert message to appear and I couldn’t implement it in filter.
I decided to try to do with the pop()
and if()
, in parts worked, the warning appears correctly, but the pop()
does not erase the record made.
Does anyone have any idea what they might do?
I’ll leave the code below.
var convidados = []
var idadeMinima = 18
var barrados = []
function cadastrar() {
var nome = document.getElementById('nome').value
convidados[nome] = {nome:document.getElementById('nome').value , idade:Number(document.getElementById('idade').value) , genero:document.getElementById('genero').value , rg:document.getElementById('rg').value , cpf:document.getElementById('cpf').value}
filtrarIdade()
}
function filtrarIdade(){
var nome = document.getElementById('nome').value
if(convidados[nome].idade>idadeMinima){
document.getElementById('alerta').innerHTML = 'O convidado foi cadastrado com sucesso!'
} else{
var barrados = convidados.pop()
document.getElementById('alerta').innerHTML = `A idade mínima do evento é ${idadeMinima}!`
}
}
It would not be easier to validate before entering the record?
– Woss
It would, but I hadn’t thought of it, when I did it solved.
– gabrielgs81
If your problem is solved put as an answer what you did to solve and choose as the right answer to close the question.
– Leticia Rosa
I’ll do it, thanks, I’m new at stackoverflow, I’m learning about the practices.
– gabrielgs81