Find the phones in stock
Use filter() to keep only phones where inStock is true. Print their model names with map().
Arrays and filters · Beginner
Work through 19 coding practice exercises in JavaScript, TypeScript, Python, SQL and JSON. Run a starter, use a hint when needed and compare your result with the explained solution. These are self-guided exercises without automated grading.
Browse all coding toolsEach exercise includes a runnable starter, hints and an explained solution. Choose a topic you already recognise, then try its edge case.
Use filter() to keep only phones where inStock is true. Print their model names with map().
Arrays and filters · Beginner
Calculate price × quantity for each item and add the amounts. Try a for...of loop first, then reduce().
Loops and aggregation · Beginner
Create a Ticket type and a describeTicket function that returns the passenger and seat separated by " — ".
Typed parameters · Beginner
Split the sentence on whitespace and count each word with a dictionary. Print the counts for code and learn.
Dictionaries and loops · Beginner
Write a query that groups rows by customer and returns SUM(amount), ordered by customer.
GROUP BY and SUM · Beginner
Replace single quotes with double quotes, quote property names and remove the trailing comma so the document is valid JSON.
JSON syntax · Beginner
Use a Set to remove duplicate tags while keeping the order in which each tag first appears. Print the unique tags on one line, separated by a comma and a space.
Sets and unique values · Beginner
Sort the books from cheapest to most expensive without changing the original array. Print the titles on one line, then print the title of the first item in the original array to prove it did not move.
Sorting objects · Beginner
Use reduce to build an object that counts how many orders have each status. Print the paid, pending and shipped counts separated by spaces.
Counting with reduce · Beginner
Turn a lowercase title into Title Case. Split it into words, capitalize the first letter of each word, join the words again and print the result.
Strings and arrays · Beginner
Write activeNames(users: User[]): string[] so that it returns the names of the active users. Print the result joined by a comma and a space.
Interfaces and arrays · Beginner
Write a generic function first<T>(items: T[]): T | undefined that returns the first item of an array, or undefined for an empty array. Print the result for a number array, a string array and an empty array.
Generics · Beginner
Use a list comprehension to build a list containing the square of every even number. Print the list.
List comprehensions · Beginner
Define average(numbers) so that it returns the mean of a list of numbers, and returns 0 for an empty list. Print the average of scores and of an empty list.
Functions and edge cases · Beginner
For each word, print True if it reads the same backwards when you ignore upper and lower case, and False otherwise.
Strings and slicing · Beginner
Select the name and price of products that are in stock and cost less than 100. Order the rows from the cheapest to the most expensive.
WHERE and ORDER BY · Beginner
List each customer name together with the amount of each of their orders. Include only customers who have orders, and order the rows by name and then amount.
JOIN · Beginner
Count the visits for each page, keep only pages visited more than once and order the result with the highest count first.
GROUP BY and HAVING · Beginner
Make this configuration valid JSON. Remove the comment, replace the Python-style True with a JSON boolean and add the missing comma between the two hosts.
JSON syntax · Beginner