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

123
Visualizações
Why is this function not reading one of my parameters?

I have this function in JS that should return 'not sold'/'sold to {name}'/'unknown ticket id' depending on the value/existence of the "ticketId" key in the "tickets" object, but it just returns 'unknown ticket id' for any 'ticketId' value regardless of whether it is actually null or has a value assigned to it in the 'tickets' object.

  export function ticketStatus(tickets, ticketId) {
  if (tickets["ticketId"] === null) {
    return 'not sold';
  } else if (tickets["ticketId"] === undefined) {
    return 'unknown ticket id';
  } else {
    return ('sold to ' + tickets["ticketId"]);
  }
}

VSCode says that the "ticketId" parameter is declared but never read in the function. I'm guessing that's why the function keeps returning the undefined option. In that case, why is 'ticketId' not being read as it should?

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

0

"ticketId" is a string, not the variable as you intended.

You probably meant tickets[ticketId]:

export function ticketStatus(tickets, ticketId) {
  if (tickets[ticketId] === null) {
    return "not sold";
  } else if (tickets[ticketId] === undefined) {
    return "unknown ticket id";
  } else {
    return "sold to " + tickets[ticketId];
  }
}
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