Challenges
From your first function to promises. Solutions are checked by tests right in your browser.
74 challenges
Basics
0 of 9 solved
- 01Beginner
Sum of two numbers
Your first function: take two numbers and return their sum.
Keywords: basics · functions
- 02Beginner
Even number
Decide whether a number is even.
Keywords: basics · conditions
- 03Beginner
Degrees Fahrenheit
Convert a temperature from Celsius to Fahrenheit and round to tenths.
Keywords: numbers
- 04Beginner
The larger of two
Return the larger of two numbers using the ternary operator.
Keywords: conditions
- 05Beginner
Price arrow
Show whether a price went up, down or stayed the same.
Keywords: conditions
- 06Beginner
Clamp to a range
Keep a number from going past a minimum and a maximum.
Keywords: numbers · conditions
- 07Beginner
Leap year
Work out whether a year is a leap year by the Gregorian calendar rules.
Keywords: conditions · numbers
- 08Beginner
Letter grade
Convert a score to a letter grade on a scale.
Keywords: conditions
- 09Beginner
FizzBuzz for one number
An interview classic: Fizz, Buzz, FizzBuzz or the number itself.
Keywords: conditions · numbers
Arrays and strings
0 of 20 solved
- 10Beginner
Cart total
Add up every number in an array.
Keywords: arrays · loops
- 11Beginner
Average rating
Compute the arithmetic mean of an array.
Keywords: arrays · numbers
- 12Beginner
Largest number
Find the largest number in an array — without Math.max.
Keywords: arrays · loops
- 13Beginner
Count occurrences
Count how many times an element appears in an array.
Keywords: arrays · loops
- 14Beginner
A range of numbers
Build an array of every integer from `from` to `to`.
Keywords: arrays · loops
- 15Beginner
The last N
Return the last n items of an array.
Keywords: arrays
- 16Beginner
Reverse a string
Reverse a string without the built-in reverse method.
Keywords: strings · loops
- 17Beginner
Capitalize
Make the first letter of a string a capital.
Keywords: strings
- 18Beginner
How many vowels
Count the vowels in a string.
Keywords: strings
- 19Beginner
Truncate with an ellipsis
Shorten a long text to a given length and add "…".
Keywords: strings
- 20Beginner
Mask a card number
Show only the last 4 digits of a card number.
Keywords: strings
- 21Beginner
No duplicates
Keep each value once, preserving the order.
Keywords: arrays · Set
- 22Intermediate
Palindrome
Check whether a phrase reads the same in both directions.
Keywords: strings · loops
- 23Intermediate
Any duplicates?
Check whether any value appears twice in an array.
Keywords: arrays · Set
- 24Intermediate
Split into pages
Divide an array into pieces of a given size.
Keywords: arrays · loops
- 25Intermediate
Check a sudoku row
Check that a sudoku row has no repeated digits.
Keywords: arrays · sudoku
- 34Beginner
Remove empty values
Remove null, undefined and empty strings from an array without losing 0 and false.
Keywords: arrays
- 35Beginner
Title Case
Capitalize the first letter of every word.
Keywords: strings · arrays
- 36Beginner
Count the words
Count the words in a text without being fooled by extra spaces.
Keywords: strings · arrays
- 37Beginner
A page address from a title
Turn an article title into part of a URL: hello-world.
Keywords: strings · regular expressions
Objects and array methods
0 of 13 solved
- 26Beginner
Full name
Build a full name from a user object.
Keywords: objects · strings
- 27Beginner
Order total
Compute an order's cost: price × quantity for each line.
Keywords: objects · arrays
- 28Beginner
Delivery fee
Read a nested value that may be missing, and fall back to a default.
Keywords: objects
- 29Beginner
Default settings
Merge default settings with the user's saved settings.
Keywords: objects
- 30Intermediate
Only the fields you need
Build a new object from just the listed keys.
Keywords: objects
- 31Intermediate
Letter frequency
Count how many times each letter appears.
Keywords: objects · strings
- 32Intermediate
Invert an object
Swap an object's keys and values.
Keywords: objects
- 33Intermediate
Group by a property
Sort objects into groups based on a property's value.
Keywords: objects · arrays
- 38Intermediate
Names of adults
Filter and transform an array with filter and map.
Keywords: arrays · higher-order functions
- 39Intermediate
Cheapest first
Sort prices in ascending order without changing the original array.
Keywords: arrays · array methods
- 40Intermediate
The most expensive item
Find the product with the highest price using `reduce`.
Keywords: arrays · array methods
- 41Intermediate
Leaderboard
Return the names of the top `n` players by score.
Keywords: arrays · array methods
- 42Intermediate
One shared list
Combine an array of arrays into one array (one level deep).
Keywords: arrays · array methods
Closures, recursion and classes
0 of 6 solved
- 46Intermediate
Counter
Return a function that gives the next number on every call.
Keywords: functions · closures
- 47Intermediate
Multiplier factory
Return a function that multiplies by a preset number.
Keywords: functions · closures
- 48Advanced
Only once
Wrap a function so it runs only on the first call.
Keywords: functions · closures
- 49Advanced
Remember the answers
Wrap a slow function so it never computes the same answer twice.
Keywords: functions · closures
- 61Intermediate
Comment counter
Count every comment in a thread — replies to replies included.
Keywords: recursion · trees
- 62Intermediate
A cart class
A `Cart` class: add an item, remove an item, get the total and the number of pieces.
Keywords: classes · this · objects
Errors and async
0 of 8 solved
- 43Intermediate
A safe JSON.parse
Parse JSON, and if it's broken, return a default value.
Keywords: errors
- 44Intermediate
Age from a form
Turn text from a form field into an age, or return null if it's invalid.
Keywords: numbers · strings
- 45Intermediate
Sign-up validation
Check a user's data and throw an error if something's wrong.
Keywords: errors · conditions
- 50Advanced
A promise and error handling
Wait for a promise's result and handle a rejection properly.
Keywords: promises · async/await · errors
- 51Advanced
All the prices at once
Load several prices in parallel and wait for all of them.
Keywords: promises · async/await
- 52Advanced
Don't wait forever
Limit how long to wait for a promise using `Promise.race`.
Keywords: promises · errors
- 53Advanced
Try again
Repeat an async operation until it succeeds or the attempts run out.
Keywords: promises · async/await · errors
- 54Advanced
A widget dashboard
Load every widget in parallel and show the ones that worked, even if some failed.
Keywords: promises · async/await
Interview classics
0 of 6 solved
- 55Intermediate
Two sum
Find two numbers that add up to a target — in one pass.
Keywords: arrays · interviews
- 56Intermediate
Anagram
Check whether two strings are made of the same letters.
Keywords: strings · interviews
- 57Intermediate
Brackets in order
Check that every bracket is opened and closed correctly.
Keywords: strings · interviews
- 58Intermediate
Roman numerals
Convert a number from 1 to 3999 to Roman numerals.
Keywords: strings · interviews
- 59Intermediate
Rotate a table
Swap the rows and columns of a two-dimensional array.
Keywords: arrays · interviews
- 60Advanced
Binary search
Find a number in a sorted array by discarding half each time.
Keywords: arrays · interviews · algorithms
JavaScript in the browser
0 of 6 solved
- 63Intermediate
Cats looking for a home
Render a list from an array of objects: exact markup, classes, `data-id` and a message for an empty list.
Keywords: DOM · createElement · textContent · classList
- 64Intermediate
Tabs
Switch a product's tabs with one handler for all of them.
Keywords: events · delegation · DOM
- 65Intermediate
Joining the club
Check a sign-up form: five fields, clear errors next to the fields and no page reload.
Keywords: forms · DOM · validation
- 66Intermediate
A customer's orders
Load a customer and their orders with two parallel requests and build a summary.
Keywords: fetch · HTTP · promises
- 67Intermediate
Recent searches
Keep the latest queries in `localStorage`: newest first, no repeats, five at most — and no crashes on corrupted data.
Keywords: localStorage · JSON · arrays
- 68Intermediate
Filtering to-dos
Draw the to-do list by a filter and say how many are shown.
Keywords: DOM · arrays · state
Like in real projects
0 of 6 solved
- 69Intermediate
The cat cafe receipt
Split a receipt into modules: the price goes to `utils/money.js`, an order line to `cart/lines.js`, and the assembly to `main.js`.
Keywords: modules · import and export
- 70Intermediate
New version
Bump a package version by the semver rules: patch, minor or major.
Keywords: strings · npm
- 71Intermediate
The first bad commit
Find the commit that broke everything — with as few checks as possible. That's how git bisect works.
Keywords: debugging · binary search · git bisect
- 72Intermediate
Tests for a password
Write a test suite that passes the correct code and catches every mutant.
Keywords: testing · edge cases
- 73Intermediate
Resolve the conflict
Remove merge-conflict markers, keeping your version, theirs, or both.
Keywords: strings · git · state machine
- 74Advanced
A report for several cities
Weather for several cities at once: parallel requests, partial failures and the warmest city.
Keywords: fetch · promises · errors