frontend for java full stack development coursera week 2 answers
Javascript - Practice Quiz
1. What is the purpose of the "name" attribute in an HTML form input element?
- To specify the label for the input field.
- To define the type of input field.
- To provide a unique identifier for the input field.
- To set a default value for the input field.
2. Which of the following are valid arithmetic operators in JavaScript?
- +
- –
- *
- All of the above
3. Which of the following is a conditional statement in JavaScript?
- for loop
- if/else statement
- Both A and D
- while loop
4. Which of the following are looping structures in JavaScript?
- if/else statement
- switch statement
- for loop
- while loop
DOM - Practice Quiz
5. What is the Document Object Model (DOM) in JavaScript?
- A data type used to store documents
- A programming language used to create documents
- A programming interface for web documents
- A file format used to store documents
6. How can you access and manipulate DOM elements with JavaScript?
- By using CSS to modify DOM elements
- By using JavaScript methods and properties
- By using HTML to modify DOM elements
- By using a server-side programming language to modify DOM elements
7. What are events and event listeners in JavaScript?
- JavaScript functions used to create animations
- HTML tags used to define web page structure
- Actions or occurrences that happen in the browser, and event listeners are functions that respond to those actions or occurrences
- JavaScript methods used to modify DOM elements
8. How can you respond to user input, such as clicks and key presses, with JavaScript?
- By using HTML tags to define web page structure
- By using CSS to style web page elements
- By using event listeners in JavaScript
- By using JavaScript methods to modify DOM elements
9. What is the purpose of creating interactive user interfaces with events in JavaScript?
- To modify DOM elements with CSS
- To define the structure of web pages with HTML
- To allow users to interact with web pages and provide dynamic functionality
- To modify JavaScript data types and variables
Javascript & DOM - Graded Quiz
10. Which method is used to create a new element in the DOM using JavaScript?
- createElement()
- createNode()
- addElement()
- appendChild()
11. What is AJAX an abbreviation for?
- Asynchronous JavaScript and XML
- Asynchronous JSON and XML
- Asynchronous JavaScript and XHTML
- Asynchronous JSON and XHTML
12. Which method is used to send an AJAX request in JavaScript?
- sendRequest()
- createRequest()
- XMLHttpRequest()
- ajaxRequest()
13. What is the purpose of the try-catch statement in JavaScript?
- It is used to define a block of code to be executed repeatedly.
- It is used to define a block of code to be executed conditionally.
- It is used to handle errors and exceptions that may occur during code execution.
- It is used to terminate the execution of a function or loop.
14. What is the purpose of the catch block in a try-catch statement?
- It defines the code to be executed if the try block encounters an error or exception.
- It defines the code to be executed if a specific condition is met.
- It defines the code to be executed unconditionally after the try block.
- It defines the code to be executed before the try block.
15. Which method is used to remove an element from the DOM using JavaScript?
- removeChild()
- deleteElement()
- removeElement()
- detachElement()
16. What is the purpose of the load event in AJAX?
- It is triggered when an error occurs during the AJAX request.
- It is triggered when the response from the AJAX request is received.
- It is triggered when the AJAX request is sent.
- It is triggered when the DOM is fully loaded and parsed.
17. Which statement is used to throw a custom error or exception in JavaScript?
- raiseError()
- throwException()
- throwError()
- throw
18. What is the purpose of the finally block in a try-catch statement?
- It defines the code to be executed if the try block encounters an error or exception.
- It defines the code to be executed if a specific condition is met.
- It defines the code to be executed unconditionally after the try block.
- It defines the code to be executed regardless of whether an error or exception occurred.
19. Which method is used to handle AJAX errors in JavaScript?
- handleError()
- onerror()
- catchError()
- onreadystatechange()
20. Which method is used to add an event listener to an element in JavaScript?
- attachEvent()
- addEventListener()
- bindEvent()
- bindListener()
21. What is the purpose of the preventDefault() method in JavaScript?
- It is used to prevent the default behavior of an event.
- It is used to prevent the execution of a function.
- It is used to prevent the propagation of an event.
- It is used to prevent the bubbling of an event.
22. Which statement is used to define a JavaScript function?
- createFunction()
- defineFunction()
- function
- newFunction()
23. What is the scope of a variable declared inside a function in JavaScript?
- Global scope
- Function scope
- Block scope
- Window scope
24. What is the purpose of the return statement in a JavaScript function?
- It is used to terminate the execution of a function and return a value.
- It is used to define the input parameters of a function.
- It is used to assign a value to a variable within a function.
- It is used to catch and handle errors or exceptions in a function.
25. What is the purpose of the getElementById() method in JavaScript?
- It is used to get the value of an input element.
- It is used to get the text content of an HTML element.
- It is used to get a reference to an HTML element based on its ID.
- It is used to get the class name of an HTML element.
26. What is the purpose of the innerHTML property in JavaScript?
- It is used to retrieve the CSS styles applied to an element.
- It is used to modify the ID of an HTML element.
- It is used to get or set the HTML content within an element.
- It is used to retrieve the value of an input element.
27. What is the purpose of the catch block in a try-catch-finally statement?
- It defines the code to be executed if the try block encounters an error or exception.
- It defines the code to be executed if the finally block encounters an error or exception.
- It defines the code to be executed unconditionally after the try block.
- It defines the code to be executed before the try block.
28. Which method is used to add a CSS class to an HTML element using JavaScript?
- addStyleClass()
- setClass()
- modifyClass()
- classList.add()
29. What is the purpose of the throw statement in JavaScript?
- It is used to terminate the execution of a function or loop.
- It is used to define a custom error message.
- It is used to catch and handle errors or exceptions.
- It is used to throw a user-defined error or exception.