Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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 answers
Answer question

0

Add a space between count and decision

  return count + " " + decision;
about 4 years ago · Juan Pablo Isaza Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!