Web Programming - JavaScript Test 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

If you need to include JavaScript code inside an HTML file, then where should you place the JavaScript code inside the HTML document and why?

Before the body tag ending, because the html needs to run first.

The full form of BOM is ____________.

Browser Object Model

The procedures associated with an object are called ______.

Methods

Explain why JavaScript is a loosely typed language with an example.

Loosely typed because you don't declare variables. The data type can also be changed after being declared.

What method is used to convert Javascript string to object?

parse

Which method of the Array class removes the last element from the end of an array?

pop()

Which method returns all the elements in a document that match the selector?

querySelectorAll("p figure img")

Create two arrays array1 and array2 that contain the following elements 1,2,3,4,5 and 6,7,8,9,0 respectively. Mention 2 ways that the arrays can be merged to a third party which will contain the elements 1,2,3,4,5,6,7,8,9,0

var array3 = array1.concat(array2); var array3 = array1 + ',' + array2;

Which of the following statements creates an empty object with the name newObj?

var newObj = [];

Provide a code snippet that creates an array and assigns the numbers from 1 to 25 to the array. The code snippet then only prints the even numbers from the array to the webpage.

var number = [] for (var i=1;1<=25;i++) { number[i]=i; if(number[i]%2===0) { document.write(number[i]+" "); } }

Assume that an array number1 contains the elements 3,6,9,12,15. Using array manipulation (array methods, e.g push(), pop(), shift(), unshift(), slice(), splice(), etc.), provide a one-line statement that will convert the array elements to the following: 3,6,9,6,3 and will assign to a second array named number 2.

var number1 = [3,6,9,12,15]; number1.splice(3,2,6,3); var number2 = number1;

Assume, there is a list in the HTML file. Provide a statement that would access the type of the second li element in the document and assign it to a variable named option2.

var option2 = document.getElementByTagName("li")[1].type;

Assume that, in an HTML file there are 3 forms, and all the forms have 5 objects (elements) each. Provide the code snipper using which the 2nd object from the 2nd form can be accessed.

var value = document.forms[1].elements[1];

Which Web Storage does not have an expiration date?

Local Storage

What value of the selectedIndex property of a select object corresponds to no selection

-1

The strict equal operator in JavaScript is:

===

What is an anonymous function? Provide an example that takes 2 integer parameters x and y, and returns the quotient (division) if y is not equal to 0.

An anonymous function doesn't have a function name function(x,y) { if(y!==0){ return x/y; } }

Where can you find JavaScript Error Messages in a browser?

Console

The full form of DOM is ____________.

Document Object Model

The code that tells a browser what to do in response to a specific event on a specific element is called a(n)

Event Handler

In a try catch block, which statement executes regardless of whether it's associated try block throws an exception or not?

Finally

To make a window the active window, you use the ______ method of the Window object.

Focus()

To execute the same statement or command block for all the properties within a custom object, you can use the ______ statement.

For/In

What are the different types of errors in JavaScript?

Syntax, Runtime, Logic

Which form element is useful for limiting user options to a set of choices?

Text input box

A(n) _____ variable is a variable that never had a value assigned to it, has not been declared or does not exist.

Undefined

Which of the following is not a falsy value?

Unknown

During debugging, there are two different statements that you can add to your code to provide you with additional information. One of them is:

console.log()

What is the best way of handling events in JavaScript and why? Give an example of how a "click" event can be handled. You can make the necessary changes

addEventListener() method; var submit = document.getElementByID("submitButton");submit.addEventListener("click", showMessage, false);

Which method displays a dialog box with an OK button?

alert()

Name two methods you can use to add (not create a node) a node to the DOM tree, and explain the difference between them.

appendChild()[the end] and insertBefore()[beginning]

Assume that there is a paragraph element in the HTML file. Provide the code snipper that uses 2 different ways (methods) to print the message "Hello" in the paragraph. You can make additional assumptions if needed.

document.querySelector("p").innerHTML = "Hello"; document.getElementByTagName("p").innerHTML = "Hello";

What built in JavaScript function do you use to test whether a value is not a number?

isNan()


Set pelajaran terkait

Missouri Life and Accident and Health Quiz 4

View Set

vaned real estate - unit 1 : real property + ownership quiz

View Set

Ch 7 Video Pros and Cons of Buying a Franchise

View Set

MKT 322 Consumer Behavior Exam 3

View Set