Here are 20 tasks to help you practice JavaScript variables, operators, conditional statements, and loops. These are a mix of practical and theoretical tasks:
- Create a variable to store your name, age, and whether you're a student. Print them to the console.
- What is the difference between
let,const, andvarin JavaScript? - Declare three different types of variables: a number, a string, and a boolean. Use
typeofto display their types. - Explain what happens when you try to assign a value to a
constvariable after it’s been declared.
- Write an expression using arithmetic operators that evaluates to 25.
- Demonstrate the difference between
==and===with an example. - Use assignment operators (
+=,*=, etc.) to manipulate a variable's value. - What is the result of the expression:
5 + '5'and why?
- Write an if-else statement to check if a number is positive, negative, or zero.
- Create a program that takes a user's age and checks if they are old enough to vote (18+).
- Write a condition to check if a number is divisible by both 3 and 5.
- What is the purpose of the
else ifblock in conditional statements? Provide a scenario.
- Write a
forloop that prints numbers from 1 to 10. - Create a
whileloop that prints even numbers between 2 and 20. - Use a loop to calculate the factorial of a number (e.g., 5! = 120).
- Explain the difference between a
forloop and ado...whileloop.
- Write a program that asks for a number and prints whether it’s odd or even using a loop and condition.
- Create a loop that sums numbers from 1 to 100 and prints the result.
- Using a loop and condition, print all numbers from 1 to 50 that are divisible by 7.
- Write a program that prints the multiplication table (1 to 10) for a given number.