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

148
Views
Countdown won't return "Kaboom!" when finished

Can someone please tell me what I did wrong and point me in the right direction? It should countdown from 5, 4, 3, 2, 1, Kaboom!

Problem to solve

Here is my code:

let count = 6;
let message = "Start over.";

const handleRequest = (request) => {
  const url = new URL(request.url);

  if (url.pathname.includes("count") && count > 0) {
    count--;
    return new Response(count);
  } if (url.pathname.includes("count") && count <= 0) {
      return new Response("Kaboom!");
  } else {
    return new Response(message);
  }
};

I get this error:

test output: 
Countdown is 5, 4, 3, 2, 1, Kaboom!
AssertionError: Values are not equal:


[Diff] Actual / Expected

-   0
+   Kaboom!

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The task is to return 'Kaboom!' as the sixth event. Contrary, your code returns 0 because it still enters the first if clause when count is 1.

You need to adapt your conditional logic to make sure 'Kaboom!' is returned after the count of 1 has been returned. Following should work:

let count = 6;
let message = "Start over.";

const handleRequest = (request) => {
  const url = new URL(request.url);

  if (url.pathname.includes("count") && count > 1) {
    count--;
    return new Response(count);
  } if (url.pathname.includes("count") && count <= 1) {
      return new Response("Kaboom!");
  } else {
    return new Response(message);
  }
};
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!