Welcome to the JavaScript Practice Questions repository! This repository contains a variety of JavaScript exercises aimed at helping you improve your coding skills. Whether you're a beginner looking to learn the basics or an experienced developer aiming to sharpen your skills, these questions cover a wide range of topics.
- Print Variable Value: Assign a value to a variable and print it on the console.
- Arithmetic Operations: Perform arithmetic operations on two variables and print the results.
- Area of Triangle: Calculate and print the area of a triangle given its three sides.
- Sum of Integers: Compute the sum of two integers, with special handling for identical values.
- Accept and Print Number: Prompt the user for a number and print it on the console.
- Greet User: Prompt the user for their name and greet them.
- Accept and Print Sum: Prompt the user for two numbers, calculate their sum, and print it with a message.
- Greet User with Age: Prompt the user for their name and age, then greet them with their age.
- Find Greatest Number: Compare two numbers and print the greater one.
- Gender Greeting: Prompt the user for their gender and print a corresponding greeting.
- Handle Gender Input: Extend the previous program to handle incorrect gender inputs gracefully.
- Check Even or Odd: Check if a number is even or odd.
- Voter Eligibility: Determine if a user is eligible to vote based on their age.
- Years to Eligibility: Extend the voter eligibility program to print how many years until the user is eligible.
- Find Largest of Three Numbers: Compare three numbers and print the largest one.
- Electricity Bill Calculation: Prompt the user for electricity usage and calculate the bill based on rates.
- Tax Calculation: Prompt the user for their salary and calculate the tax amount.
- Triangle Classification: Determine the type of triangle based on its sides.
- Leap Year Check: Determine if a given year is a leap year.
- Grade Assignment: Assign a grade based on marks obtained by a student.
- Print Hello World: Print "Hello World" a specified number of times.
- Print Natural Numbers: Print natural numbers up to a specified number.
- Reverse Loop: Print numbers in reverse order using a for loop.
- Multiplication Table: Print the multiplication table for a given number.
- Sum of Numbers: Calculate the sum of natural numbers up to a specified number.
- Special Print: Print custom messages for multiples of three, five, or both.
- Factorial Calculation: Calculate the factorial of a number.
- Sum of Even/Odd Numbers: Calculate the sum of even and odd numbers within a range.
- Divisible Numbers: Print numbers divisible by three or five within a range.
- Factors of a Number: Print all factors of a given number.
- Sum of Factors: Calculate the sum of factors of a number.
- Perfect Number Check: Check if a number is perfect or not.
- String Concatenation: Concatenate a string multiple times.
- Separate Digits: Separate each digit of a number and print it on a new line.
- Prime Number Check: Check if a number is prime or not.
- Create Array of Fruits: Create an array containing three different types of fruits and log each fruit to the console.
- Check Fruit Existence: Write a program that checks if a specific fruit exists in the fruits array from the previous question.
- Create Array of Even Numbers: Create an array containing even numbers from 2 to 10 using a loop.
- Sum of Array Elements: Write a loop to find and print the sum of all elements in an array of numbers.
- Join Array Elements: Write a JavaScript program to join all elements of an array into a string.
- Find Largest Number in Array: Find the largest number in an array of numbers using a loop and conditional statements.
- Sort Array: Write a JavaScript program to sort the items of an array.
- Find Most Frequent Item: Write a JavaScript program to find the most frequent item in an array.
- Square Array Elements: Square the value of every element in the array and create a new array.
- Capitalize Array Elements: Take an array of strings containing words in lowercase and transform it into an array where each word is capitalized.
- Add Prefix to Array Elements: Transform an array of strings by adding a prefix to each string using map().
- Convert Celsius to Fahrenheit: Given an array of temperatures in Celsius, create a new array that converts each temperature to Fahrenheit.
- Filter Positive Numbers: Given an array of numbers (positive and negative), filter it to get only the positive numbers.
- Filter Even Numbers: Filter an array of numbers to only include the even numbers.
- Filter by Length: Given an array of strings, filter it to obtain only the words that have more than 5 characters.
- Reverse Array: Reverse the order of elements in an array without using the reverse method.
- Create Person Object: Create an object named person with properties for name, age, and city. Print each property to the console.
- Add Property to Object: Add a new property, occupation, to the person object created in the previous question and print the updated object.
- Create Calculator Object: Create an object called calculator with methods for addition, subtraction, multiplication, and division. Use these methods to perform some calculations.
- Book Object Array: Create an object representing a book with properties for title, author, and year. Store multiple book objects in an array.
- Print Book Titles: Write a function called printBooks that takes an array of book objects and prints their titles to the console.
- Filter Even Numbers: Write a function called filterEvenNumbers that takes an array of numbers, filters out the even ones, and returns a new array.
- Calculate Average Grade: Write a program that iterates through an array of objects representing students, calculates their average grade, and prints whether they pass or fail based on a passing threshold.
- Calculate BMI: Implement a function called calculateBMI that takes an object representing a person with properties height and weight and returns their BMI.
- Sort Books by Year: Write a function called sortBooksByYear that takes an array of book objects and returns a new array of books sorted by year.
- Library Simulation: Create a program that simulates a library. It should have an array of book objects, a method to borrow a book, and a method to return a book.
- Calculate Average Grade: Write a program that iterates through an array of objects representing students, calculates their average grade, and prints whether they pass or fail based on a passing threshold.
- Calculate BMI: Implement a function called calculateBMI that takes an object representing a person with properties height and weight and returns their BMI.
- Sort Books by Year: Write a function called sortBooksByYear that takes an array of book objects and returns a new array of books sorted by year.
- Library Simulation: Create a program that simulates a library. It should have an array of book objects, a method to borrow a book, and a method to return a book.