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

274
Visualizações
Why is my JavaScript code not accepted as the right answer?

I am trying to do this Javascript exercise: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

I am wondering why the solution below is not an accepted answer:

let count = 0;

function cc(card) {
  // Only change code below this line
  const low = [2, 3, 4, 5, 6];
  const high = [10, 'J', 'Q', 'K', 'A'];

  if (low.includes(card)) {
    count += 1;
  }

  else if (high.includes(card)) {
    count -= 1;
  }

  let decision;

  if (count > 0) {decision = "Bet"}
  else {decision = "Hold"}

  return count + decision;
  // Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A'); 

When I am comparing it to accepted answers I don't see what they are doing differently. One thing that is not clear to me in the assignment is that should return be called every time or only after the last function call (cc('A');).

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

0

Add a space between count and decision

  return count + " " + decision;
about 4 years ago · Juan Pablo Isaza Relatório

0

You are giving an answer in the wrong format. Just missing the space between count and decision.

Incorrect:return count + decision;

Correct:return count +" "+ decision;

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