50+ JavaScript Coding Challenges for Beginners (Solve Them in Your Browser)
The best way to learn JavaScript is by writing code — lots of it. These 50+ coding challenges are designed for beginners and cover the fundamental building blocks of programming: loops, functions, arrays, strings, and more. Work through them at your own pace, run each solution directly in your browser, and watch your JavaScript skills grow one challenge at a time. Whether you are learning on your own or a teacher looking for ready-made exercises for your coding class, you'll find plenty here to keep students engaged and challenged.
Illustrated JavaScript Coding Course
New to JavaScript? Check out the Illustrated JavaScript Coding Course e-book — a beginner-friendly, visual guide to learning JavaScript from scratch by drawing and animating on a browser canvas. Now on sale!
The coding challenges in this article are intended for code newbies, therefore the solutions are implemented using only simple / classical programming elements. Feel free to read through each solution and experiment with it in the interactive playground provided. Once you understand how it works, the best next step is to close it and try to solve the challenge from scratch in a fresh code editor at codeguppy.com. That's where the real learning happens!
The code is making use of the codeguppy specific function println() to print the results. If you want to run these solutions outside CodeGuppy, just replace println() with console.log() then run them using your browser console tool or node.js.
Coding challenge #1: Print numbers from 1 to 10
A classic first challenge. Use a for loop to count from 1 to 10 and print each number. It's the simplest way to get comfortable with loops.
Coding challenge #2: Print the odd numbers less than 100
Similar to the previous challenge, but this time you only want every other number. Notice how changing the loop's step value filters the output.
Coding challenge #3: Print the multiplication table with 7
A loop can do the repetitive math for you. This challenge shows how to build a formatted multiplication table for the number 7 using string concatenation inside a loop.
Coding challenge #4: Print all the multiplication tables with numbers from 1 to 10
Now take the previous idea further with nested loops — a loop inside a loop. The outer loop picks the number and the inner loop generates its table. Functions help keep things tidy.
Coding challenge #5: Calculate the sum of numbers from 1 to 10
A loop doesn't just have to print things — it can accumulate a result. Here you use a running total variable and add to it on each iteration.
Coding challenge #6: Calculate 10!
The factorial of a number is the product of all integers from 1 up to that number. This challenge is just like the sum challenge, but using multiplication instead of addition.
Coding challenge #7: Calculate the sum of odd numbers greater than 10 and less than 30
Combine what you've learned about loops and conditions: iterate through a range and only add the numbers that match a specific rule.
Coding challenge #8: Create a function that will convert from Celsius to Fahrenheit
Functions let you package a formula and reuse it. This challenge applies a simple mathematical formula and is a good introduction to writing functions that accept input and return a result.
Coding challenge #9: Create a function that will convert from Fahrenheit to Celsius
The inverse of the previous challenge. Same idea, reversed formula — a good reminder that functions are just reusable recipes.
Coding challenge #10: Calculate the sum of numbers in an array of numbers
Arrays store collections of values. This challenge introduces looping over an array's elements to compute a total — a pattern you'll use constantly in JavaScript.
Coding challenge #11: Calculate the average of the numbers in an array of numbers
Build on the previous challenge: once you have the sum, dividing by the number of elements gives you the average. A simple but very practical function.
Coding challenge #12: Create a function that receives an array of numbers and returns an array containing only the positive numbers
This challenge introduces filtering — going through an array and keeping only the elements that satisfy a condition. Three solutions are shown: a classic for loop, a for...of loop, and the built-in filter() method.
Solution 1
Solution 2
Solution 3
Coding challenge #13: Find the maximum number in an array of numbers
Loop through all elements keeping track of the largest value seen so far. This "running maximum" pattern is fundamental to many algorithms.
Coding challenge #14: Print the first 10 Fibonacci numbers without recursion
The Fibonacci sequence is a famous series where each number is the sum of the two before it. This iterative approach uses two variables that leapfrog each other through the sequence.
Coding challenge #15: Create a function that will find the nth Fibonacci number using recursion
Recursion means a function that calls itself. This is an elegant (though not the most efficient) way to express the Fibonacci definition directly in code.
Coding challenge #16: Create a function that will return a Boolean specifying if a number is prime
A prime number has no divisors other than 1 and itself. The solution tests potential divisors up to the square root of the number — a classic optimisation worth understanding.
Coding challenge #17: Calculate the sum of digits of a positive integer number
Convert the number to a string, then loop through each character, convert it back to a digit, and add it to a running total. A nice exercise mixing strings and numbers.
Coding challenge #18: Print the first 100 prime numbers
Combine the isPrime() function from challenge #16 with a while loop that keeps searching until it has found enough primes. A good example of reusing functions you already wrote.
Coding challenge #19: Create a function that will return in an array the first "nPrimes" prime numbers greater than a particular number "startAt"
A more flexible version of the previous challenge: the function takes parameters so you can ask for any number of primes starting from any point. Notice how nicely the isPrime() helper fits in.
Coding challenge #20: Rotate an array to the left 1 position
Rotating left means the first element moves to the end. JavaScript's built-in shift() and push() array methods make this a one-liner.
Coding challenge #21: Rotate an array to the right 1 position
The mirror image of the previous challenge: the last element moves to the front using pop() and unshift().
Coding challenge #22: Reverse an array
Walk through the array backwards and push each element into a new array. A straightforward exercise in index manipulation.
Coding challenge #23: Reverse a string
Strings and arrays share many similarities. Here you walk the string backwards character by character, building a new reversed string along the way.
Coding challenge #24: Create a function that will merge two arrays and return the result as a new array
Combine two arrays into one by pushing all elements from each into a fresh array. This is the manual version of the spread operator — useful to understand before using shortcuts.
Coding challenge #25: Create a function that will receive two arrays of numbers as arguments and return an array composed of all the numbers that are either in the first array or second array but not in both
This is the symmetric difference of two sets. A number qualifies only if it appears in one array but not the other — a good workout for combining loops and the includes() method.
Coding challenge #26: Create a function that will receive two arrays and will return an array with elements that are in the first array but not in the second
Similar to the previous challenge but one-directional: keep only the elements from the first array that are absent from the second. Think of it as subtracting one set from another.
Coding challenge #27: Create a function that will receive an array of numbers as argument and will return a new array with distinct elements
Remove duplicate values from an array. Two solutions are provided: one that checks the result array as it grows, and another that avoids revisiting duplicates already accounted for.
Solution 1
Solution 2
Coding challenge #28: Calculate the sum of first 100 prime numbers
Another use of the isPrime() helper — this time to collect and add up the first 100 primes. Shows how a well-written helper function can be reused across many problems.
Coding challenge #29: Print the distance between the first 100 prime numbers
How far apart are consecutive prime numbers? This challenge tracks the previous prime and prints the gap each time a new one is found — a simple but revealing pattern.
Coding challenge #30: Create a function that will add two positive numbers of indefinite size. The numbers are received as strings and the result should be also provided as string.
JavaScript numbers have limited precision for very large values. By working with the digits directly as strings — just like you would do on paper — you can add numbers of any size. Two different approaches are shown.
Solution 1
Solution 2
Coding challenge #31: Create a function that will return the number of words in a text
Counting words means detecting the transitions between separators and non-separator characters. Two clean implementations are shown — both walk the string one character at a time but track the boundaries differently.
Solution 1
Solution 2
Coding challenge #32: Create a function that will capitalize the first letter of each word in a text
Walk the string and uppercase any character that follows a separator. A practical string-processing challenge that reinforces the word-boundary detection from the previous challenges.
Coding challenge #33: Calculate the sum of numbers received in a comma delimited string
Split the string on commas, parse each piece as a floating-point number, and sum them up. A very common real-world pattern when processing CSV-style data.
Coding challenge #34: Create a function that will return an array with words inside a text
A more complete word extractor that tracks the start and end index of each word and slices it out of the text. Useful groundwork for any text-parsing task.
Coding challenge #35: Create a function to convert a CSV text to a "bi-dimensional" array
Split on newlines to get rows, then split each row on a separator to get columns. The result is a 2D array — the foundation of working with tabular data in JavaScript.
Coding challenge #36: Create a function that converts a string to an array of characters
A single call to Array.from() does the job. Short but useful — it shows how JavaScript's built-in methods can replace manual loops.
Coding challenge #37: Create a function that will convert a string in an array containing the ASCII codes of each character
Every character has a numeric code under the hood. charCodeAt() exposes it. This challenge is a stepping stone toward understanding how text is represented in memory.
Coding challenge #38: Create a function that will convert an array containing ASCII codes in a string
The reverse of the previous challenge: turn a list of numeric codes back into readable text using String.fromCharCode().
Coding challenge #39: Implement the Caesar cypher
A simple classical cipher that shifts each letter by a fixed number of positions in the alphabet. A great introduction to encryption concepts and modular arithmetic.
Coding challenge #40: Implement the bubble sort algorithm for an array of numbers
Bubble sort is one of the most famous sorting algorithms. It repeatedly compares adjacent elements and swaps them if they're out of order, gradually pushing larger values to the end.
Coding challenge #41: Create a function to calculate the distance between two points defined by their x, y coordinates
Apply the Pythagorean theorem in code. This is a fundamental building block for anything involving positions on a screen — from games to maps.
Coding challenge #42: Create a function that will return a Boolean value indicating if two circles defined by center coordinates and radius are intersecting
Two circles overlap if the distance between their centres is less than the sum of their radii. This challenge reuses the getDistance() function from the previous one — a great example of composing small functions into bigger solutions.
Coding challenge #43: Create a function that will receive a bi-dimensional array as argument and a number and will extract as a unidimensional array the column specified by the number
Think of a 2D array as a table. This challenge extracts a single column from it — a common operation when working with structured data like spreadsheets or databases.
Coding challenge #44: Create a function that will convert a string containing a binary number into a number
parseInt() accepts a radix (base) as a second argument, making binary-to-decimal conversion a one-liner. A good reminder that JavaScript has powerful built-in tools.
Coding challenge #45: Create a function to calculate the sum of all the numbers in a jagged array (array contains numbers or other arrays of numbers on an unlimited number of levels)
A jagged array can nest arrays inside arrays to any depth. Recursion is the natural tool here: if an element is an array, call the same function on it; if it's a number, add it to the total.
Coding challenge #46: Find the maximum number in a jagged array of numbers or array of numbers
Same nested-array structure as above, but this time you're hunting for the largest value. Two approaches are shown: one using recursion and one using an explicit stack — a great comparison of two fundamental techniques.
Solution 1
Solution 2
Coding challenge #47: Deep copy a jagged array with numbers or other arrays in a new array
Copying an array with the assignment operator just copies the reference. To get a truly independent clone of a nested structure, you need to recurse into it and copy each level manually.
Coding challenge #48: Create a function to return the longest word(s) in a string
Extract all words, then find the maximum word length, and finally collect every word that matches that length. There could be more than one — so the result is an array.
Coding challenge #49: Shuffle an array of strings
Random ordering is useful in games, quizzes, and simulations. The solution uses the Fisher–Yates shuffle algorithm — the gold standard for unbiased array shuffling.
Coding challenge #50: Create a function that will receive n as argument and return an array of n unique random numbers from 1 to n
Fill an array with numbers 1 to n, then shuffle it. The result is a random permutation with no repeats — exactly what you need for things like card games or lottery draws.
Coding challenge #51: Find the frequency of characters inside a string. Return the result as an array of objects. Each object has 2 fields: character and number of occurrences.
Iterate over every character and keep a running count for each one. The result is an array of objects — a nice introduction to storing structured data and building frequency tables.
Coding challenge #52: Calculate Fibonacci(500) with high precision (all digits)
Standard JavaScript numbers can't represent Fibonacci(500) accurately. This challenge extends the big-number addition from challenge #30 to compute exact Fibonacci results for very large indices.
Coding challenge #53: Calculate 70! with high precision (all digits)
70! is an astronomically large number — far beyond what JavaScript's Number type can handle exactly. Using the big-number multiplication technique, you can compute all its digits precisely.
A note for CS teachers
These 50+ challenges make an excellent addition to any JavaScript curriculum or coding class. They are carefully ordered by difficulty — starting with simple loops and progressing through functions, arrays, strings, recursion, algorithms, and big-number arithmetic — so you can pick the right challenge for the right moment in your course.
Each challenge is self-contained, runs entirely in the browser with no setup required, and comes with a working solution that students can study, modify, and experiment with. That makes them just as useful for guided classroom exercises as for independent practice or homework assignments.
A few ideas for using them in your teaching:
- Warm-up exercises — start a class with a quick challenge to get students thinking in code
- Homework assignments — ask students to solve a challenge from scratch and explain their approach
- Code review sessions — compare multiple solutions (like the ones shown for challenges #12, #27, #30, #31, and #46) to spark discussion about different ways to solve the same problem
- Assessment — use the challenges as the basis for short quizzes or practical tests
If you are looking for a structured, beginner-friendly platform where your students can write and run JavaScript directly in the browser, check out codeguppy.com — it is designed with students and educators in mind.
Read more blog articles Browse JavaScript projectsAbout codeguppy
CodeGuppy is a FREE coding platform for schools and independent learners. If you don't have yet an account with codeguppy.com, you can start by visiting the registration page and sign-up for a free account. Registered users can access tons of fun projects!

Follow @codeguppy on Twitter for coding tips and news about codeguppy platform. For more information, please feel free to contact us.
