JavaScript lab questions
1. Write a JavaScript program to display "Welcome to JavaScript Programming"
using alert() and console.log().
2. Declare variables of different data types (string, number, boolean, undefined, null)
and display their types using typeof operator.
3. Write a JavaScript program to swap two numbers using a temporary variable.
4. Create a simple calculator using JavaScript that takes two numbers and an operator
(+, -, *, /) and returns the result.
5. Write a JavaScript program to find the largest of three numbers using if...else
and prompt() for input.
6. Create a program that prints numbers from 1 to 100, but for multiples of 3, print
"Fizz"; for multiples of 5, print "Buzz"; and for both, print "FizzBuzz".
7. Write a JavaScript function that returns the factorial of a given number using for
loop.
8. Write a function to check if a string is a palindrome.
9. Create a program using while loop to reverse a number (e.g., 12345 → 54321).
10. Create a program that asks the user's name using prompt() and then shows a
greeting using alert() or confirm().
11. Create a simple webpage with a button. When clicked, it should change the
background color using JavaScript and DOM events.
12. Create an object named student with properties like name, age, rollNo, and a
method to display the student's info.
13. Create an array of 5 numbers. Write a function to calculate and display the sum and
average of the numbers.
14. Write a program to add, remove, and display elements in an array using methods
like push, pop, shift, and unshift.
15. Use Date object to display the current date and time in dd/mm/yyyy hh:mm:ss
format.
16. Write a JavaScript program using Math object to generate a random number
between 1 and 100 and check if it is even or odd.
17. Write a regular expression to validate an email address using RegExp object.
18. Create a simple HTML form with fields: name, email, and password. Use
JavaScript to validate that no field is left empty.
19. Write a script to create and read cookies for storing a user's theme preference (e.g.,
dark or light mode).
20. Use basic jQuery to hide/show a paragraph when a button is clicked.