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

272
Visualizações
Javascript: How do I use the same function with different parameters?

I would be forever grateful if you could enlighten me how to get it to work. Currently when I run it it gives the alert upon the first entered username.

let userName1;
let userName2;
let userName3;

alcoholAgeCheck();
alcoholAgeCheck(userName2);
alcoholAgeCheck(userName3);

function alcoholAgeCheck() {
  userName1 = prompt('Enter name');

  if (userName1 === userName2 || userName1 === userName3) {
    alert('Sorry, you may only use the same name once');
  } else if (userName2 === userName1 || userName2 === userName3) {
    alert('Sorry, you may only use the same name once');
  }
}

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

0

Save all the previous inputs in a variable, and check whether the new input is in the set.

const userNames = new Set();

function alcoholAgeCheck() {
  userName = prompt('Enter name');
  if (userNames.has(userName)) {
    alert('Sorry, you may only use the same name once');
  } else {
    userNames.add(userName);
  }
}

alcoholAgeCheck();
alcoholAgeCheck();
alcoholAgeCheck();
console.log(Array.from(userNames));

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