Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
Need the output of the inputs to be pushed into the <div>

I'm trying to get the user inputs to be pushed out as a message into a <div> via the button press after confirming that all the inputs are filled and the correct password has been entered. That part works fine but my forEach is not working:

If the user has input a number value lower than 18, I want an if that types out via push "Your name is UName and you are Age years old, you are not of legal age", or else the same result as above but ending with "...you are of legal age".

Any idea how I should go forth?

let nameElement = document.getElementById("UNameInput");
let faultElement = document.getElementById("errorOutput");
let ageElement = document.getElementById("AgeInput");
let clickElement = document.getElementById("button");
let passwordElement = document.getElementById("PasswordInput");
clickElement.addEventListener("click", function(e) {

  let feedback = [];
  if (UNameInput.value === '' || UNameInput.value === null) {
    feedback.push('Name input missing')
  }

  if (AgeInput.value === '' || AgeInput.value === null) {
    feedback.push('Age input missing')
  } else if (PasswordInput.value !== 'IHM') {
    feedback.push('Password is not valid')
  } else {
    feedback.forEach((item, i) => {
      if (item.AgeInput < 18) {
        feedback.push("You are not of not legal age")
      } else {
        feedback.push(" You are of legal age ")
      }
    });
  }
  if (feedback.length > 0) {
    e.preventDefault()
    faultElement.innerText = feedback.join(", ")
  }
});
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="JSny.js" defer></script>
</head>

<body>
  <div id="errorOutput"></div>
  <p id="output"></p>
  <div>
    <label for="UNameInput">Name Input</label>
    <input id="UNameInput" name="name" type="text">
  </div>
  <div>
    <label for="AgeInput">Age Input</label>
    <input id="AgeInput" name="age" type="number">
  </div>
  <div>
    <label for="PasswordInput">Password Input</label>
    <input id="PasswordInput" name="password" type="password">
  </div>
  <button id="button">Submit</button>
</body>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are using AgeInput instead of ageElement in the if statement.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda