JavaScript exercises for beginners

43 coding challenges from the CurlyScript Dojo, from your first function to promises and classes. Write your answer on the page and press Check: real tests tell you what works. Every exercise has hints and a solution, and all of them are free.

White belt

Variables, strings, if and else, and loops. Start here. 14 exercises.

  1. Convert days to seconds Turn days into seconds. After Grade 1: Variables: Boxes With Labels.
  2. Write a greeting function Build a friendly greeting from a name. After Grade 2: Data Types: What Goes in the Boxes?.
  3. Get the initials from a name Turn a full name into initials. After Grade 2: Data Types: What Goes in the Boxes?.
  4. Work out a bill with a service charge Work out a bill with a service charge. After Grade 3: Operators: Math, Comparisons & Logic.
  5. Check if a number is even or odd Label any whole number. After Grade 3: Operators: Math, Comparisons & Logic.
  6. Find the largest of three numbers Find the largest number without Math.max. After Grade 4: Making Decisions: if, else & Friends.
  7. Turn a score into a letter grade Turn a score into a letter grade. After Grade 4: Making Decisions: if, else & Friends.
  8. Check for a leap year Is February 29 a real day this year? After Grade 4: Making Decisions: if, else & Friends.
  9. Name the day of the week with switch Use switch to name a day. After Grade 4: Making Decisions: if, else & Friends.
  10. Add up the numbers from 1 to n Sum every number from 1 to n. After Grade 5: Loops: Doing Things Over and Over.
  11. Count the vowels in a string Count the a, e, i, o and u in any text. After Grade 5: Loops: Doing Things Over and Over.
  12. Reverse a string Reverse a string with a loop. After Grade 5: Loops: Doing Things Over and Over.
  13. FizzBuzz The world’s most famous coding interview question. After Grade 5: Loops: Doing Things Over and Over.
  14. Print a staircase pattern with nested loops Draw a staircase with nested loops. After Grade 5: Loops: Doing Things Over and Over.

Green belt

Arrays, objects, functions, errors and closures. 13 exercises.

  1. Find the average of an array Average a list of scores. After Grade 7: Arrays: Lists of Things.
  2. Check if a string is a palindrome Does it read the same backwards? After Grade 7: Arrays: Lists of Things.
  3. Remove duplicates from an array Remove repeated items, keeping the order. After Grade 7: Arrays: Lists of Things.
  4. Split an array into chunks Split an array into groups. After Grade 7: Arrays: Lists of Things.
  5. Convert a string to title case Capitalize the first letter of every word. After Grade 7: Arrays: Lists of Things.
  6. Find the longest word in a sentence Find the longest word in a sentence. After Grade 7: Arrays: Lists of Things.
  7. Count how often each word appears Count how often each word appears. After Grade 8: Objects: Describing Things With Labels.
  8. Merge default settings with user options Combine defaults with a user’s choices. After Grade 8: Objects: Describing Things With Labels.
  9. Summarize an array of objects Summarize a shopping list of objects. After Grade 8: Objects: Describing Things With Labels.
  10. Throw an error when dividing by zero Throw a helpful error instead of returning Infinity. After Summer School: Debugging: Becoming a Bug Detective.
  11. Find and fix three bugs This function has three bugs. Find them all! After Summer School: Debugging: Becoming a Bug Detective.
  12. Build a counter with a closure Use a closure to build custom counters. After Grade 9: Scope, Hoisting & Closures.
  13. Write a once() function Wrap a function so it only ever runs once. After Grade 9: Scope, Hoisting & Closures.

Black belt

Array methods, async code, classes and small real-world tools. 16 exercises.

  1. Group array items by a key Sort things into labeled groups. After Grade 10: Array Power Tools: map, filter & reduce.
  2. Sort and format a leaderboard Filter, sort and format the top players. After Grade 10: Array Power Tools: map, filter & reduce.
  3. Flatten a nested array Turn nested arrays into one flat list. After Grade 10: Array Power Tools: map, filter & reduce.
  4. Check if two words are anagrams Are two words made of the same letters? After Grade 10: Array Power Tools: map, filter & reduce.
  5. Write a Caesar cipher Send secret messages by shifting letters. After Grade 10: Array Power Tools: map, filter & reduce.
  6. Convert numbers to Roman numerals Convert numbers like the ancient Romans. After Grade 10: Array Power Tools: map, filter & reduce.
  7. Write a memoize function Cache results so slow work only happens once. After Grade 13: Modern JavaScript Power-Ups.
  8. Clean up messy data Tidy messy records with modern JavaScript. After Grade 13: Modern JavaScript Power-Ups.
  9. Return a promise that resolves after a delay Your first asynchronous function. After Freshman Year: Asynchronous JavaScript: Waiting Without Freezing.
  10. Add a timeout to a promise Give up on a promise that takes too long. After Freshman Year: Asynchronous JavaScript: Waiting Without Freezing.
  11. Run promises in parallel and handle failures Cook in parallel and handle failures. After Freshman Year: Asynchronous JavaScript: Waiting Without Freezing.
  12. Build a stack class A class for last-in, first-out storage. After Sophomore Year: Classes & Object-Oriented JavaScript.
  13. Classes and inheritance: a virtual pet Classes, inheritance and a little game logic. After Sophomore Year: Classes & Object-Oriented JavaScript.
  14. Parse CSV text into objects Turn spreadsheet text into objects. After Junior Year: Modules, Node.js & npm: Working Like a Pro.
  15. Build a mini test runner Build the thing that checks your code. After Junior Year: Modules, Node.js & npm: Working Like a Pro.
  16. Write the logic for a quiz app The state logic behind a quiz app. After Senior Year: Capstone Projects: Build Real Apps.

Want the lessons too?

CurlyScript is a free game that teaches JavaScript from zero: short lessons, an explanation after every answer, and a test at the end of every grade.

Start learning