JavaScript Notes
Master JavaScript fundamentals with 20+ beginner-level practice problems covering variables, loops, functions, strings, and arrays. Each problem includes solution code and expected output.
Welcome to the WoHoTech JavaScript Beginner Practice Set! This page contains 25 carefully crafted problems that cover all fundamental JavaScript concepts. Each problem includes a clear problem statement, a working solution, and the expected output.
Who Is This For?
- Students learning JavaScript for the first time
- Anyone preparing for junior developer interviews
- Self-learners who want to solidify their fundamentals
Topics Covered
Variables & Data Types → Operators → Conditionals (if/else) → Loops (for, while) → Functions → Strings → Basic Arrays
Problem 2: Check Even or Odd
Problem: Write a function that checks whether a given number is even or odd.
function checkEvenOdd(num) {
if (num % 2 === 0) {
return num + " is Even";
} else {
return num + " is Odd";
}
}
console.log(checkEvenOdd(4));
console.log(checkEvenOdd(7));
console.log(checkEvenOdd(0));4 is Even 7 is Odd 0 is Even
Problem 3: Find the Largest of Three Numbers
Problem: Write a function that takes three numbers and returns the largest one.
function findLargest(a, b, c) {
if (a >= b && a >= c) {
return a;
} else if (b >= a && b >= c) {
return b;
} else {
return c;
}
}
console.log(findLargest(10, 25, 15));
console.log(findLargest(99, 45, 99));
console.log(findLargest(3, 7, 5));25 99 7
Problem 4: Celsius to Fahrenheit Conversion
Problem: Write a function to convert temperature from Celsius to Fahrenheit. Formula: F = (C × 9/5) + 32
function celsiusToFahrenheit(celsius) {
let fahrenheit = (celsius * 9/5) + 32;
return celsius + "°C = " + fahrenheit + "°F";
}
console.log(celsiusToFahrenheit(0));
console.log(celsiusToFahrenheit(100));
console.log(celsiusToFahrenheit(37));0°C = 32°F 100°C = 212°F 37°C = 98.6°F
Problem 5: Calculate Factorial
Problem: Write a function to calculate the factorial of a number using a loop. Factorial of n = n × (n-1) × (n-2) × ... × 1
5! = 120 0! = 1 8! = 40320
Problem 6: Multiplication Table
Problem: Write a program to print the multiplication table of a given number.
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
Problem 7: Sum of Natural Numbers
Problem: Write a function to calculate the sum of first N natural numbers using a while loop.
Sum of first 10: 55 Sum of first 50: 1275 Sum of first 100: 5050
Problem 8: Reverse a String
Problem: Write a function that reverses a string without using the built-in reverse() method.
olleh tpircSavaJ hceToHoW
Problem 9: Check Palindrome
Problem: Write a function that checks if a given string is a palindrome (reads the same forwards and backwards).
true true false true
Problem 10: FizzBuzz
Problem: Print numbers from 1 to 20. For multiples of 3 print "Fizz", for multiples of 5 print "Buzz", for multiples of both print "FizzBuzz".
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
Problem 11: Count Vowels in a String
Problem: Write a function that counts the number of vowels in a given string.
hello: 2 JavaScript: 3 aEiOu: 5
Problem 12: Sum of Array Elements
Problem: Write a function that calculates the sum of all elements in an array.
15 60 0
Problem 13: Find the Largest Element in an Array
Problem: Write a function to find the largest element in an array without using Math.max().
9 200 -1
Problem 14: Fibonacci Series
Problem: Write a function to print the first N numbers of the Fibonacci series. Each number is the sum of the two preceding ones.
First 8: 0, 1, 1, 2, 3, 5, 8, 13 First 10: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Problem 15: Check Prime Number
Problem: Write a function that checks if a number is prime. A prime number is only divisible by 1 and itself.
function isPrime(num) {
if (num <= 1) return false;
if (num <= 3) return true;
if (num % 2 === 0) return false;
for (let i = 3; i <= Math.sqrt(num); i += 2) {
if (num % i === 0) return false;
}
return true;
}
console.log("2 is prime:", isPrime(2));
console.log("17 is prime:", isPrime(17));
console.log("25 is prime:", isPrime(25));
console.log("1 is prime:", isPrime(1));2 is prime: true 17 is prime: true 25 is prime: false 1 is prime: false
Problem 16: Count Digits in a Number
Problem: Write a function that counts how many digits are in a given number.
12345: 5 100: 3 -9876: 4 0: 1
Problem 17: Reverse an Array
Problem: Write a function to reverse an array without using the built-in reverse() method.
[ 5, 4, 3, 2, 1 ] [ 'c', 'b', 'a' ] [ true, false, true ]
Problem 18: Check Leap Year
Problem: Write a function to check whether a given year is a leap year. A year is leap if divisible by 4, except century years which must be divisible by 400.
function isLeapYear(year) {
if (year % 400 === 0) return true;
if (year % 100 === 0) return false;
if (year % 4 === 0) return true;
return false;
}
console.log("2024:", isLeapYear(2024));
console.log("2026:", isLeapYear(2026));
console.log("2000:", isLeapYear(2000));
console.log("1900:", isLeapYear(1900));2024: true 2026: false 2000: true 1900: false
Problem 19: Find Second Largest in Array
Problem: Write a function to find the second largest number in an array.
40 8 90
Problem 20: Simple Calculator Using Functions
Problem: Write a calculator program that performs basic arithmetic operations using functions.
10 + 5 = 15 20 - 8 = 12 6 * 7 = 42 15 / 3 = 5 10 / 0 = Cannot divide by zero
Problem 21: Remove Duplicates from Array
Problem: Write a function to remove duplicate values from an array using basic loops.
[ 1, 2, 3, 4, 5 ] [ 'a', 'b', 'c' ] [ 10 ]
Problem 22: Generate a Simple Star Pattern
Problem: Write a program to print a right-angled triangle star pattern with N rows.
* * * * * * * * * * * * * * * * * * * *
Problem 23: Sum of Digits of a Number
Problem: Write a function that calculates the sum of all digits in a given number.
function sumOfDigits(num) {
num = Math.abs(num);
let sum = 0;
while (num > 0) {
sum += num % 10;
num = Math.floor(num / 10);
}
return sum;
}
console.log("123:", sumOfDigits(123));
console.log("9999:", sumOfDigits(9999));
console.log("-456:", sumOfDigits(-456));
console.log("1001:", sumOfDigits(1001));123: 6 9999: 36 -456: 15 1001: 2
Problem 24: Find Average of Array Elements
Problem: Write a function to calculate the average (mean) of all numbers in an array.
Average of [10, 20, 30, 40, 50]: 30 Average of [5, 15, 25]: 15 Average of [100]: 100 Average of [2, 4, 6, 8]: 5
Problem 25: Title Case a Sentence
Problem: Write a function that converts a sentence to title case (first letter of each word capitalized, rest lowercase).
Hello World Javascript Is Fun Practice Makes Perfect The Quick Brown Fox
Key Takeaways
- Start simple — Variables, operators, and conditionals are the building blocks. Master them before moving to complex problems.
- Loops are essential — Almost every problem involves iteration. Practice
for,while, anddo...whileuntil they feel natural.
- Functions make code reusable — Every solution above is wrapped in a function. This is a habit you must build early.
- Strings and arrays share patterns — Reversing, searching, and counting use similar loop logic for both strings and arrays.
- Edge cases matter — Zero, negative numbers, empty inputs — always think about what could break your code.
- Read the output carefully — Before running any code, predict what it will print. This builds mental model accuracy.
Tips for Practice
- Solve without looking at the solution first. Spend at least 10-15 minutes trying on your own.
- Type the code, don't copy-paste. Typing builds muscle memory for syntax.
- Modify each problem — change inputs, add edge cases, rewrite with different loop types.
- Explain your solution out loud (rubber duck debugging). If you can explain it, you understand it.
- Track your progress — mark which problems you solved without help and revisit the rest.
- Practice daily — Even 2-3 problems per day builds strong fundamentals over a few weeks.
- Use browser console — Open DevTools (F12) and test your code immediately.
Next Step: Once you've completed all 25 problems confidently, move on to the Intermediate Practice Set covering objects, higher-order functions, closures, and DOM manipulation.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for JavaScript Beginner Practice Problems — 20+ Coding Exercises 2026.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this JavaScript Master Course topic.
Search Terms
javascript-complete-guide, javascript master course, javascript, complete, guide, practice, beginner, javascript beginner practice problems — 20+ coding exercises 2026
Related JavaScript Master Course Topics