JavaScript Coding Exercises for Beginners
coding problems 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.
Problem: Write a function that takes a string and returns it reversed.
Input: "hello"
โ Output: "olleh"
๐ก Hint: Use
split()
,reverse()
, andjoin()
.
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.
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.
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.
Problem: Convert a sentence so the first letter of each word is capitalized.
Input: "hello world"
โ Output: "Hello World"
๐ก Hint: Use
split()
,map()
, andjoin()
.
Problem: Write a function that counts the number of vowels (a, e, i, o, u
) in a string.
๐ก Hint: Use
match()
with regex.
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
orfilter()
.
Problem: Return the total sum of numbers in an array.
๐ก Hint: Use
reduce()
.
Problem: Write a function to return the factorial of a given number.
Input: 5
โ Output: 120
๐ก Hint: Use recursion or a loop.
Problem: Write a function that checks if a number is prime.
๐ก Hint: Prime numbers are only divisible by 1 and themselves.
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!
javascript exercises
, beginner coding problems
, javascript practice problems
, interview prep JavaScript
, JavaScript coding questions