question 1 Assuming that the href attributes of each <a> element contains the UR
ID: 3591307 • Letter: Q
Question
question 1
Assuming that the href attributes of each <a> element contains the URL for an image, what does the code that follows do?
var flowers = document.getElementsByTagName("a");
var i, flower, image;
for ( i = 0; i < flowers.length; i++ ) {
flower = flowers[i];
image = new Image();
image.src = flower.href;
}
It puts the contents of all <a> elements into an array named flowers.
It creates a new Image object for each image in the flowers array.
It preloads each Image object.
All of the above.
A and B only.
question 2
What will futureValue contain after the for loop has been executed one time?
var years = 10;
var annualRate = 10;
var futureValue = 1000;
annualRate = annualRate / 100;
for ( i = 1; i <= years; i++ ) {
futureValue += futureValue * annualRate;
}
(1pts)
1000
1100
11000
1010
question 3
Which method of the Element interface returns true if the element has the specified attribute?
(1pts)
getAttribute()
hasAttribute()
getElementsByName()
setAttribute()
question 4
The childNodes property of the Node interface
(1pts)
returns the text that’s stored in the first child node
returns an array of Node objects that represent the child nodes of a node
returns an array of String objects that contain the text that’s stored in each child node
returns a null value if the node has no child nodes
question 5
Code Example 2-1
1. var myAge, newAge;
2. myAge = prompt("How old are you?");
3. myAge = parseInt(myAge);
4. newAge = 18 - myAge;
5. alert("You will be eligible to vote in " + newAge + " years");
(Refer to Code Example 2-1) What would be returned if the user entered “fifteen” at the prompt?
(1pts)
You will be eligible to vote in undefined years
You will be eligible to vote in NaN years
You will be eligible to vote in years
nothing, the program would not run
Explanation / Answer
Question 1:
Answer - All of the Above
Reason :- Var Flowers stores all the list of url arddress, and in the for loop for each flower creates an image object by calling new Image(), by assigning flower.href to image src it preloads each image object . So the answer is all of the above
Question 2
Answer - 1100
from Question annualRate = 10/100 = 0.1
Since the for loop is for only one time futureValue += futureValue *annualRate becomes
1000 += 1000 * 0.1 => 1000 += 100 => 1100
Question 3
Answer - hasAttribute ()
Because getAttribute returns the value of the specified attribute , hasAttribute returns true or false if the specified element is there or not,getElementsbyName returns elements with the specified name and setAttribute helps to set the attribute
Question 4
Answer :- returns an array of Node objects that represent the child nodes of a node
Child nodes are returning an array of node objects , not the text file or string , Can acces the property through the object. if the node has no child then it will return false not null value. So the answer is 2 nd one
Question 5
Answer - You will be eligible to vote in NaN years
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.