exam questions

Exam 98-382 All Questions

View all questions & answers for the 98-382 exam

Exam 98-382 topic 1 question 6 discussion

Actual exam question from Microsoft's 98-382
Question #: 6
Topic #: 1
[All 98-382 Questions]

You are writing a JavaScript program for Contoso Suites that will output HTML.
You need to output each room type on a new line using the correct method.
You create the following code for the function. Line numbers are included for reference only.

You need to insert the correct code at Line 9. Which line should you use?

  • A. document.getElementById("body").innerHTML = rooms[i] + line.innerHTML;
  • B. document.getElementById("para").innerHTML += rooms[i] + line.innerHTML;
  • C. document.getElementById("para").innerHTML += i + rooms + line.innerHTML;
  • D. document.getElementById("body").innerHTML += rooms + i;
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ClauDia
Highly Voted 3 years, 11 months ago
document.getElementById("body").innerHTML+=rooms[i] + line.innerHTML
upvoted 6 times
...
Sathya235
Most Recent 3 years, 5 months ago
None of the answer given is correct. The correct solution is document.getElementById("para").innerHTML+=rooms[i]+"<br>";
upvoted 2 times
...
rodrigoandrade
3 years, 11 months ago
The answer B print this results. Single Double Single Triple Single Double Single Suite Single Double Single Triple Single Double Single The correct answer should be: var line = document.getElementById("para"); var breakLine= document.getElementById("para").innerHTML; var rooms = ["Single", "Double", "Triple", "Suite"]; var i=0; for(i=0;i<rooms.length;i++){ document.getElementById("para").innerHTML += rooms[i] + breakLine; }
upvoted 3 times
...
joan
4 years, 3 months ago
Why do you have wrong answers marked, it is very confusing. This one for example- the correct answer is A
upvoted 2 times
...
becky_intelletive
4 years, 4 months ago
None of these answers are correct. document.getElementById("para") returns a reference to the HTML element, not a copy of the current HTML element. This means that innerHTML gets the CURRENT html. The line document.getElementById("para").innerHTML += rooms[i] + line.innerHTML; is equivalent to document.getElementById("para").innerHTML += rooms[i] + document.getElementById("para").innerHTML; In other words, it's: newHTML = currentHTML + newRoomType + currentHTML; And you end up with a ridiculously long answer that goes Single Double Single Triple Single Double etc. The correct way to do it would be to first get the line break by calling .innerHTML on line 05. This will retrieve and return the value of the HTML AT THAT MOMENT. Then instead of calling line.innerHTML on line 09, you would simply call line. Here is a CodePen example to illustrate the two: https://codepen.io/becky-intelletive/pen/RwGvJEm
upvoted 3 times
...
ouzss
4 years, 7 months ago
he said in new line so it is answer B
upvoted 1 times
...
sirT0mci0
5 years, 1 month ago
ignore my last comment. Answer B is correct.
upvoted 1 times
...
sirT0mci0
5 years, 1 month ago
@02rids Thats true but we are adding </br> tag using line.innerHTML in every line. IMO answer A is correct
upvoted 2 times
...
02rids
5 years, 3 months ago
i think option B is correct. Because we have to show each room type in different line.
upvoted 4 times
...
KSinha
5 years, 5 months ago
Please recheck the answer, should it be option A
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...