JavaScript Coding Exercises for Beginners

4/14/2025

coding problems for beginners

Go Back
coding problems for beginners

Top 10 JavaScript Coding Exercises for Beginners

Level up your skills with these fun, practical JavaScript challenges.

JavaScript is one of the most popular programming languages in web development. Whether you're just starting or brushing up your skills, coding exercises are a great way to practice. In this article, weโ€™ve compiled 10 beginner-friendly JavaScript exercises with descriptions and tips to solve them.


1. Reverse a String

Problem: Write a function that takes a string and returns it reversed.
Input: "hello" โ†’ Output: "olleh"

๐Ÿ’ก Hint: Use split(), reverse(), and join().


2. Check for Palindrome

Problem: Return true if a string is a palindrome.
Input: "racecar" โ†’ Output: true

๐Ÿ’ก Hint: A string is a palindrome if it reads the same forward and backward.


3. FizzBuzz

Problem: Print numbers from 1 to 100.

  • For multiples of 3, print "Fizz".

  • For multiples of 5, print "Buzz".

  • For multiples of both, print "FizzBuzz".

๐Ÿ’ก Hint: Use if and % operator.


4. Find the Largest Number in an Array

Problem: Write a function that returns the largest number in an array.
Input: [5, 10, 2, 8] โ†’ Output: 10

๐Ÿ’ก Hint: Use Math.max() or a loop.


5. Capitalize First Letter of Each Word

Problem: Convert a sentence so the first letter of each word is capitalized.
Input: "hello world" โ†’ Output: "Hello World"

๐Ÿ’ก Hint: Use split(), map(), and join().


6. Count Vowels in a String

Problem: Write a function that counts the number of vowels (a, e, i, o, u) in a string.

๐Ÿ’ก Hint: Use match() with regex.


7. Remove Duplicates from an Array

Problem: Remove all duplicate elements from an array.
Input: [1, 2, 2, 3, 4, 4, 5] โ†’ Output: [1, 2, 3, 4, 5]

๐Ÿ’ก Hint: Use Set or filter().


8. Sum of All Numbers in an Array

Problem: Return the total sum of numbers in an array.

๐Ÿ’ก Hint: Use reduce().


9. Factorial of a Number

Problem: Write a function to return the factorial of a given number.
Input: 5 โ†’ Output: 120

๐Ÿ’ก Hint: Use recursion or a loop.


10. Check if a Number is Prime

Problem: Write a function that checks if a number is prime.

๐Ÿ’ก Hint: Prime numbers are only divisible by 1 and themselves.


๐Ÿงช Practice Makes Perfect

These exercises help build a strong JavaScript foundation and prepare you for real-world coding. Try solving them without peeking at the solution, then use console logs to test your functions!


๐Ÿ” Keywords for SEO

javascript exercises, beginner coding problems, javascript practice problems, interview prep JavaScript, JavaScript coding questions