---
title: Create a JavaScript Coding Challenge
description: Build and test a JavaScript coding challenge in LeetLabs, with a complete example.
---

[Skip to content](https://support.learnyst.com/create-a-javascript-coding-challenge#main-content)

![Learnyst Logo-25-1.png\]](https://support.learnyst.com/hs-fs/hubfs/Learnyst%20Logo-25-1.png?height=40&name=Learnyst%20Logo-25-1.png)

- [Blogs](https://blog.learnyst.com/)
- [Product Demo](https://www.learnyst.com/product-demo)
- [Help Center](https://support.learnyst.com/?__hstc=63047858.c6632626f509e3bce8daa43b7e98f888.1712298652738.1721125968223.1721135407952.38&__hssc=63047858.1.1721135407952&__hsfp=1459259341&_gl=1*1hsz3xc*_gcl_aw*R0NMLjE3MzA4OTkxMzAuQ2p3S0NBaUF4S3k1QmhCYkVpd0FZaVctLTFMeml2UU9iS3JlNDdQaXE4Y2RDRTRPbE9iZnFVYS1sYkViTm5lcW52eHljMnNXOTRoMlRCb0N3QVVRQXZEX0J3RQ..*_gcl_au*MTM5MDI5MDc5LjE3MjU5Mzg3NTIuNjU1NTcwMzYxLjE3MzMyMzMxODAuMTczMzIzMzE3OQ..)
- [Success Stories](https://www.learnyst.com/customers/success-stories)

Open main navigation

Close main navigation

- [Blogs](https://blog.learnyst.com/)
- [Product Demo](https://www.learnyst.com/product-demo)
- [Help Center](https://support.learnyst.com/?__hstc=63047858.c6632626f509e3bce8daa43b7e98f888.1712298652738.1721125968223.1721135407952.38&__hssc=63047858.1.1721135407952&__hsfp=1459259341&_gl=1*1hsz3xc*_gcl_aw*R0NMLjE3MzA4OTkxMzAuQ2p3S0NBaUF4S3k1QmhCYkVpd0FZaVctLTFMeml2UU9iS3JlNDdQaXE4Y2RDRTRPbE9iZnFVYS1sYkViTm5lcW52eHljMnNXOTRoMlRCb0N3QVVRQXZEX0J3RQ..*_gcl_au*MTM5MDI5MDc5LjE3MjU5Mzg3NTIuNjU1NTcwMzYxLjE3MzMyMzMxODAuMTczMzIzMzE3OQ..)
- [Success Stories](https://www.learnyst.com/customers/success-stories)

 Hello, how can we help you today?

- There are no suggestions because the search field is empty.

1. [Support Center](https://support.learnyst.com/?hsLang=en)
2. [Courses](https://support.learnyst.com/courses?hsLang=en)
3. [Add Lesson](https://support.learnyst.com/courses?hsLang=en#add-lesson)

# Create a JavaScript Coding Challenge

## Build and test a JavaScript coding challenge in LeetLabs, with a complete example.

This guide shows how to build a JavaScript coding challenge in LeetLabs, with a complete example that we built and tested on Learnyst. Use it as a template for your own JavaScript exercises. Read [Create a coding challenge](https://support.learnyst.com/create-a-coding-test?hsLang=en) first for the general steps.

**On this page**

- [How input and output work in JavaScript](https://support.learnyst.com/create-a-javascript-coding-challenge#how-input-and-output-work-in-javascript)
- [Example: Sum of two numbers](https://support.learnyst.com/create-a-javascript-coding-challenge#example-sum-of-two-numbers)
- [Test it in Preview](https://support.learnyst.com/create-a-javascript-coding-challenge#test-it-in-preview)
- [Tips for JavaScript challenges](https://support.learnyst.com/create-a-javascript-coding-challenge#tips-for-javascript-challenges)
- [Practice ideas for JavaScript](https://support.learnyst.com/create-a-javascript-coding-challenge#practice-ideas-for-javascript)

### How input and output work in JavaScript

Your program reads the test case **Input** from standard input and prints its answer with `console.log`. Read all input at once with `require("fs").readFileSync(0, "utf8")`, then split it into values.

The program's printed output must match the test case **Output** exactly, including spaces and line breaks.

### Example: Sum of two numbers

Create a challenge with **Language** set to **Javascript**, then fill in each step.

**Problem Statement:**

```
Sum of Two Numbers
Read two integers a and b from a single line of input, separated by a space. Print their sum.
Example input: 2 3
Example output: 5
Constraints: -1000 <= a, b <= 1000
```

**Initial Snippet** (the starter code learners see):

```
const fs = require("fs");
const [a, b] = fs.readFileSync(0, "utf8").trim().split(/\s+/).map(Number);

// Write your code below
```

**Test Cases:**

| Title | Input | Output | Visibility |
| --- | --- | --- | --- |
| Positive numbers | `2 3` | `5` | Visible |
| Negative numbers | `-4 10` | `6` | Hidden |

**Hints:** one to explain the input is already read, and one to show how to print the result.

**Solution:**

```
const fs = require("fs");
const [a, b] = fs.readFileSync(0, "utf8").trim().split(/\s+/).map(Number);

console.log(a + b);
```

**Advanced Options:** Difficulty **Easy**, Unlock Hints After **1** code run.

### Test it in Preview

Click **Preview**, then **TAKE CHALLENGE**. Learners see the problem on the left, your starter code in the editor, and the visible test case below.

![JavaScript challenge in the learner coding screen](https://support.learnyst.com/hs-fs/hubfs/image-png-Dec-02-2026-12-26-13-7263-PM.png?width=670&height=377&name=image-png-Dec-02-2026-12-26-13-7263-PM.png)

Code that subtracts instead of adding prints -1 for the input `2 3`, so **RUN** shows **Wrong Answer**.

![Wrong Answer result](https://support.learnyst.com/hs-fs/hubfs/image-png-Dec-02-2026-12-26-14-9322-PM.png?width=670&height=377&name=image-png-Dec-02-2026-12-26-14-9322-PM.png)

The correct solution prints 5 and shows **Correct Answer**. The hidden test case is checked when the learner submits.

![Correct Answer result](https://support.learnyst.com/hs-fs/hubfs/image-png-Dec-02-2026-12-26-16-1498-PM.png?width=670&height=377&name=image-png-Dec-02-2026-12-26-16-1498-PM.png)

### Tips for JavaScript challenges

- Use `.trim()` before splitting, so a trailing newline in the input doesn't create an empty value.
- Convert text to numbers with `Number` or `parseInt`. Input is always read as text.
- Print each answer with `console.log`. Extra spaces or lines change the output and fail the test case.

### Practice ideas for JavaScript

- Reverse a string or check for a palindrome
- Find the largest number in an array
- Count vowels in a sentence
- FizzBuzz for numbers 1 to n
- Sort an array without using sort()

### What to do next

- [Create a coding challenge](https://support.learnyst.com/create-a-coding-test?hsLang=en): all the steps and options.
- [Publish and unpublish code challenges](https://support.learnyst.com/publish-and-unpublish-the-code?hsLang=en): make the challenge available for your courses.
- [Embed a coding challenge into courses](https://support.learnyst.com/embed-the-coding-challenge-into-courses?hsLang=en): add it as a lesson.

If you have questions, contact us at support@learnyst.com.

- [Get Started](https://support.learnyst.com/get-started#main-content)
- [AI Tools](https://support.learnyst.com/ai-tools#main-content)
- [Courses](https://support.learnyst.com/courses#main-content)

    - [Getting Started](https://support.learnyst.com/courses#getting-started)
    - [Build Course](https://support.learnyst.com/courses#build-course)
    - [Add Lesson](https://support.learnyst.com/courses#add-lesson)
    - [Course Settings](https://support.learnyst.com/courses#course-settings)
    - [Lesson Settings](https://support.learnyst.com/courses#lesson-settings)
    - [Course Certificate](https://support.learnyst.com/courses#course-certificate)
- [Mock test](https://support.learnyst.com/mock-test#main-content)

    - [Getting Started](https://support.learnyst.com/mock-test#getting-started)
    - [Build Mock Test](https://support.learnyst.com/mock-test#build-mock-test)
    - [GMAT Question Types](https://support.learnyst.com/mock-test#gmat-question-types)
    - [Mock test Settings](https://support.learnyst.com/mock-test#mock-test-settings)
    - [Mock Test Templates](https://support.learnyst.com/mock-test#mock-test-templates)
- [Test Series](https://support.learnyst.com/test-series#main-content)

    - [Getting Started](https://support.learnyst.com/test-series#getting-started)
    - [Build Test Series](https://support.learnyst.com/test-series#build-test-series)
    - [Settings](https://support.learnyst.com/test-series#settings)
    - [Test Series Templates](https://support.learnyst.com/test-series#test-series-templates)
- [Bundles](https://support.learnyst.com/bundles#main-content)

    - [Getting Started](https://support.learnyst.com/bundles#getting-started)
    - [Build Bundles](https://support.learnyst.com/bundles#build-bundles)
    - [Bundle Settings](https://support.learnyst.com/bundles#bundle-settings)
- [Batch](https://support.learnyst.com/batch#main-content)

    - [Batch Settings](https://support.learnyst.com/batch#batch-settings)
- [1:1 Coaching](https://support.learnyst.com/11-coaching#main-content)
- [Poll](https://support.learnyst.com/poll#main-content)
- [Track](https://support.learnyst.com/track#main-content)

    - [Getting Started](https://support.learnyst.com/track#getting-started)
    - [Track Settings](https://support.learnyst.com/track#track-settings)
- [Ebooks](https://support.learnyst.com/ebooks#main-content)
- [Podcasts](https://support.learnyst.com/podcasts#main-content)
- [Webinars](https://support.learnyst.com/webinars#main-content)
- [Digital/Custom Products](https://support.learnyst.com/digital-custom-products#main-content)
- [Free Resource](https://support.learnyst.com/free-resource#main-content)
- [Question Pool](https://support.learnyst.com/question-pool#main-content)

    - [Getting Started](https://support.learnyst.com/question-pool#getting-started)
    - [Build Question Pool](https://support.learnyst.com/question-pool#build-question-pool)
- [Quiz & Assessment](https://support.learnyst.com/quiz-assessment#main-content)

    - [Getting Started](https://support.learnyst.com/quiz-assessment#getting-started)
    - [Add Questions](https://support.learnyst.com/quiz-assessment#add-questions)
    - [Build Quiz](https://support.learnyst.com/quiz-assessment#build-quiz)
    - [Question Settings](https://support.learnyst.com/quiz-assessment#question-settings)
    - [Quiz Settings](https://support.learnyst.com/quiz-assessment#quiz-settings)
    - [Question Review Flow](https://support.learnyst.com/quiz-assessment#question-review-flow)
    - [Learner Results](https://support.learnyst.com/quiz-assessment#learner-results)
- [Classification](https://support.learnyst.com/classification#main-content)

    - [Categories](https://support.learnyst.com/classification#categories)
    - [Tags](https://support.learnyst.com/classification#tags)
- [Product Pricing](https://support.learnyst.com/product-pricing#main-content)

    - [Getting Started](https://support.learnyst.com/product-pricing#getting-started)
    - [Pricing Plans](https://support.learnyst.com/product-pricing#pricing-plans)
- [Website](https://support.learnyst.com/website#main-content)

    - [Getting Started](https://support.learnyst.com/website#getting-started)
    - [Building Website](https://support.learnyst.com/website#building-website)
    - [Website Navigation](https://support.learnyst.com/website#website-navigation)
    - [Superpower Widgets](https://support.learnyst.com/website#superpower-widgets)
    - [Sign Up Settings](https://support.learnyst.com/website#sign-up-settings)
    - [Widgets (Embeddables)](https://support.learnyst.com/website#widgets-embeddables)
- [Website Custom domain](https://support.learnyst.com/website-custom-domain#main-content)
- [Mobile Apps](https://support.learnyst.com/mobile-apps#main-content)

    - [Android](https://support.learnyst.com/mobile-apps#android)
    - [iOS](https://support.learnyst.com/mobile-apps#ios)
- [Communities](https://support.learnyst.com/communities#main-content)

    - [Learnyst Community](https://support.learnyst.com/communities#learnyst-community)
    - [Telegram Community](https://support.learnyst.com/communities#telegram-community)
- [Socials](https://support.learnyst.com/socials#main-content)
- [Gamification](https://support.learnyst.com/gamification#main-content)
- [Users](https://support.learnyst.com/users#main-content)

    - [Learners](https://support.learnyst.com/users#learners)
- [Learner Management](https://support.learnyst.com/learner-management#main-content)

    - [Learner Profile](https://support.learnyst.com/learner-management#learner-profile)
    - [Learner Actions](https://support.learnyst.com/learner-management#learner-actions)
    - [Learner Settings](https://support.learnyst.com/learner-management#learner-settings)
- [Zoho E-signin](https://support.learnyst.com/zoho-e-signin#main-content)
- [Roles and Permissions](https://support.learnyst.com/roles-and-permissions#main-content)
- [Marketing](https://support.learnyst.com/marketing#main-content)

    - [Refer Earn](https://support.learnyst.com/marketing#refer-earn)
    - [Push Message](https://support.learnyst.com/marketing#push-message)
    - [Marketing Email](https://support.learnyst.com/marketing#marketing-email)
    - [System Email](https://support.learnyst.com/marketing#system-email)
    - [Whatsapp Messenger](https://support.learnyst.com/marketing#whatsapp-messenger)
    - [Affiliates](https://support.learnyst.com/marketing#affiliates)
    - [Workflows](https://support.learnyst.com/marketing#workflows)
    - [Forms](https://support.learnyst.com/marketing#forms)
    - [Campaign](https://support.learnyst.com/marketing#campaign)
    - [CTA](https://support.learnyst.com/marketing#cta)
    - [Promo Slider](https://support.learnyst.com/marketing#promo-slider)
- [Workflows](https://support.learnyst.com/workflows#main-content)
- [Integrations](https://support.learnyst.com/integrations#main-content)

    - [Pabbly Integration](https://support.learnyst.com/integrations#pabbly-integration)
    - [Zapier Integration](https://support.learnyst.com/integrations#zapier-integration)
    - [Google Ads](https://support.learnyst.com/integrations#google-ads)
    - [Meta Ads](https://support.learnyst.com/integrations#meta-ads)
- [Newsfeed](https://support.learnyst.com/newsfeed#main-content)
- [Sales](https://support.learnyst.com/sales#main-content)
- [Ratings and Reviews](https://support.learnyst.com/ratings-and-reviews#main-content)
- [Learner Support](https://support.learnyst.com/learner-support#main-content)
- [Sub School](https://support.learnyst.com/sub-school#main-content)
- [Reports](https://support.learnyst.com/reports#main-content)

    - [Score Reports & Quiz Insights](https://support.learnyst.com/reports#score-reports-quiz-insights)
- [Content Security](https://support.learnyst.com/content-security#main-content)

    - [CourseGaurd](https://support.learnyst.com/content-security#coursegaurd)
- [School Settings](https://support.learnyst.com/school-settings#main-content)

    - [General Settings](https://support.learnyst.com/school-settings#general-settings)
    - [Learner Billing](https://support.learnyst.com/school-settings#learner-billing)
    - [Payment gateway](https://support.learnyst.com/school-settings#payment-gateway)
    - [Features](https://support.learnyst.com/school-settings#features)
    - [Security](https://support.learnyst.com/school-settings#security)
    - [Channels](https://support.learnyst.com/school-settings#channels)
- [Payments](https://support.learnyst.com/payments#main-content)

    - [Custom installments](https://support.learnyst.com/payments#custom-installments)
- [Subscriptions](https://support.learnyst.com/subscriptions#main-content)
- [Zoom integration](https://support.learnyst.com/zoom-integration#main-content)
- [Troubleshooting](https://support.learnyst.com/troubleshooting#main-content)

    - [Web – Windows](https://support.learnyst.com/troubleshooting#web-windows)
    - [Web – Mac](https://support.learnyst.com/troubleshooting#web-mac)
    - [Android app](https://support.learnyst.com/troubleshooting#android-app)
    - [General](https://support.learnyst.com/troubleshooting#general)
- [FAQs](https://support.learnyst.com/faqs#main-content)
- [Learners' Help article](https://support.learnyst.com/learners-help-article#main-content)
- [Add Ons](https://support.learnyst.com/add-ons#main-content)

- [Home](https://learnyst-1.hubspotpagebuilder.net/)
- [About Us](https://learnyst-1.hubspotpagebuilder.net/about-us)
- [Contact Us](https://learnyst-1.hubspotpagebuilder.net/contact-us)
- [Blog](https://learnyst.hs-sites-na2.com/blog)

[![Chill listening crop-3](https://support.learnyst.com/hs-fs/hubfs/Learnyst%20logo%20(2).png?width=24&height=24&name=Learnyst%20logo%20(2).png "Chill listening crop-3")](https://www.learnyst.com/)

Learnyst Support

Copyright © 2026, Learnyst Insights Pvt Ltd