EASTC Bachelor of Data science First year.
Web development module 2nd semester.
Basic JavaScript sample questions for web development module, ordered from easier to more
challenging:
1. Print "Hello, World!" to the console.
2. Declare a variable called `name` and assign your name to it. Print the variable to the
console.
3. Create two variables, `a` and `b`, and assign them the values 5 and 10. Print the sum
of `a` and `b`.
4. Declare a variable `age` and assign your age to it. Print a message saying "I am X
years old" where X is the value of `age`.
5. Write a program that swaps the values of two variables `x` and `y`.
6. Write a program that converts a temperature from Celsius to Fahrenheit. Use
functions
7. Create an array of 5 favorite colors and print the second color in the array.
8. Write a program that checks if a number is even or odd.
9. Write a program that prints numbers from 1 to 10 using a `for` loop.
10. Write a program that prints "Good Morning" if the time is less than 12, and "Good
Afternoon" otherwise.
11. Write a function called `greet` that takes a name as a parameter and prints "Hello,
[name]".
12. Write a function that takes two numbers and returns their product.
13. Create an object representing a book with properties like `title`, `author`, and `year`.
Print the title of the book.
14. Create an object representing a car with methods to start and stop the engine.
15. Write a script to change the text of an HTML element with id "demo" to "Hello,
JavaScript!".
16. Write a script to hide an HTML element with id "hideMe".
17. Write a script to create a new list element and add it to the body of the HTML
document.
18. Write a script to change the background color of a webpage when a button is clicked.
19. Write a script to display an alert when a form is submitted.
20. Write a script to display the current date and time when a button is clicked.
21. Write a script to validate that a user’s input in a text field is not empty when a form is
submitted.