0% found this document useful (0 votes)
9 views5 pages

JavaScript Group Work For 5 Members

The document consists of a series of JavaScript questions and programming tasks designed for a group of five members. It covers topics such as object literals, array manipulation, error handling, and interaction with HTML elements. Additionally, it includes exercises on regular expressions and creating functions, providing a comprehensive overview of JavaScript concepts and practical applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

JavaScript Group Work For 5 Members

The document consists of a series of JavaScript questions and programming tasks designed for a group of five members. It covers topics such as object literals, array manipulation, error handling, and interaction with HTML elements. Additionally, it includes exercises on regular expressions and creating functions, providing a comprehensive overview of JavaScript concepts and practical applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Group work for 5 members

Choose the correct answer.

1. Which symbol is used to define an object literal?

o A. []

o B. ()

o C. {}

o D. <>

2. How do you access the property name of an object student?

o A. student[name]

o B. [Link]

o C. student->name

o D. student::name

3. Which of the following is an object?

o A. "Car"

o B. 25

o C. { color: "red", model: "BMW" }

o D. true

4. What can objects contain?

o A. Only values

o B. Only functions

o C. Properties and methods

o D. Only arrays

5. Which of the following declares an array?

o A. let a = {1,2,3}

o B. let a = (1,2,3)

o C. let a = [1,2,3]
o D. let a = <1,2,3>

6. What is the index of the first element in an array?

o A. 1

o B. 0

o C. -1

o D. 2

7. Which method adds an element to the end of an array?

o A. add()

o B. insert()

o C. push()

o D. append()

8. Which method removes the last element from an array?

o A. remove()

o B. delete()

o C. pop()

o D. shift()

9. What does [Link] return?

o A. Last index

o B. Total number of elements

o C. First value

o D. Array type

10. Which keyword is used to catch errors?

o A. error

o B. handle

o C. catch

o D. fix
11. Which block contains code that may cause an error?

o A. catch

o B. try

o C. throw

o D. final

12. What happens if an error is not handled?

o A. Program continues normally

o B. Error is ignored

o C. Program may stop

o D. Error is fixed automatically

13. What is error handling?

14. Explain the use of try and catch.

15. What happens when an error is not handled in a program?

16. How do you change the content of an HTML element using JavaScript?

17. How can JavaScript respond to user events like clicking a button?

18. Explain the difference between single quotes (' ') and double quotes (" ") in JavaScript.

19. Write a JavaScript statement that updates text inside an HTML element.

20. Write a program using if…else if…else to display grades:

• A (≥80)

• B (≥70)

• C (≥60)

• D (≥50)

• F (<50)
26. Write a program using a switch statement to display the day of the week based on a
number (1–7).

27. Write a JavaScript program that calculates the sum of numbers from 1 to 100.

28. Write a program that displays the multiplication table of 5 using a loop.

29. Write a program that counts down from 10 to 1 using a while loop.

30. Write a function that calculates the area of a rectangle.

31. Write a function that accepts a student’s marks and returns "Pass" or "Fail".

32. Write a function that displays a greeting message using a given name.

33. Write a JavaScript program that stores five numbers in an array and prints them.

34. Write a program that finds the largest number in an array.

35. Write a program that loops through an array of names and displays each name.

36. Write a program that adds a new element to an array and removes the last element.

37. Write a JavaScript program that counts how many elements are in an array.

Additional Questions for revision

Objects

38. Create an object representing a student with properties: name, age, and course. Display
all values.

39. Write a program that updates one property of an object.

40. Create an object that contains a function to display a message.

41. Write a program that loops through the properties of an object and prints them.

42. Create an object representing a car and display its model and color.

JavaScript with HTML (Data Manipulation)

43. Write JavaScript code that changes the text of an HTML paragraph when a button is
clicked.
44. Write a program that displays user input inside an HTML element.

45. Write JavaScript code that shows an alert message when a button is clicked.

46. Write a program that displays the result of two numbers inside an HTML element.

47. Write JavaScript code that hides an HTML element when a button is clicked.

Regular Expressions

48. Write a JavaScript program that checks whether a string contains only letters.

49. Write a program that validates an email address using a regular expression.

50. Write a JavaScript code that checks whether a string contains a number.

51. Write a program that replaces all spaces in a string with hyphens using regex.

52. Write a JavaScript program that checks if a password is at least 8 characters long.

Error Handling

52. Write a JavaScript program using try and catch to handle an error.

53. Write a program that catches an error when dividing by zero.

54. Write a JavaScript program that displays a custom error message.

55. Write a program that uses try…catch to handle invalid input.

56. Write a JavaScript program that continues running after an error occurs.

You might also like