Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 2.03 KB

File metadata and controls

48 lines (32 loc) · 2.03 KB

Here are 20 tasks to help you practice JavaScript variables, operators, conditional statements, and loops. These are a mix of practical and theoretical tasks:


🔸 Variables & Data Types

  1. Create a variable to store your name, age, and whether you're a student. Print them to the console.
  2. What is the difference between let, const, and var in JavaScript?
  3. Declare three different types of variables: a number, a string, and a boolean. Use typeof to display their types.
  4. Explain what happens when you try to assign a value to a const variable after it’s been declared.

🔸 Operators

  1. Write an expression using arithmetic operators that evaluates to 25.
  2. Demonstrate the difference between == and === with an example.
  3. Use assignment operators (+=, *=, etc.) to manipulate a variable's value.
  4. What is the result of the expression: 5 + '5' and why?

🔸 Conditional Statements

  1. Write an if-else statement to check if a number is positive, negative, or zero.
  2. Create a program that takes a user's age and checks if they are old enough to vote (18+).
  3. Write a condition to check if a number is divisible by both 3 and 5.
  4. What is the purpose of the else if block in conditional statements? Provide a scenario.

🔸 Loops

  1. Write a for loop that prints numbers from 1 to 10.
  2. Create a while loop that prints even numbers between 2 and 20.
  3. Use a loop to calculate the factorial of a number (e.g., 5! = 120).
  4. Explain the difference between a for loop and a do...while loop.

🔸 Combining Concepts

  1. Write a program that asks for a number and prints whether it’s odd or even using a loop and condition.
  2. Create a loop that sums numbers from 1 to 100 and prints the result.
  3. Using a loop and condition, print all numbers from 1 to 50 that are divisible by 7.
  4. Write a program that prints the multiplication table (1 to 10) for a given number.