98-382 Exam QuestionsBrowse all questions from this exam

98-382 Exam - Question 6


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.

Exam 98-382 Question 6

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

Show Answer
Correct Answer: B

To correctly output each room type on a new line in the HTML paragraph element with id 'para', you need to append each room type to the current inner HTML of the 'para' element and also include the existing content of 'para'. Therefore, option B is correct as it appends the current room and the existing inner HTML to 'para', ensuring each room type is displayed on a new line.

Discussion

10 comments
Sign in to comment
ClauDia
Jun 24, 2021

document.getElementById("body").innerHTML+=rooms[i] + line.innerHTML

02rids
Mar 5, 2020

i think option B is correct. Because we have to show each room type in different line.

KSinha
Dec 31, 2019

Please recheck the answer, should it be option A

becky_intelletive
Jan 18, 2021

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

rodrigoandrade
Jun 28, 2021

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; }

sirT0mci0
May 8, 2020

@02rids Thats true but we are adding </br> tag using line.innerHTML in every line. IMO answer A is correct

joan
Feb 15, 2021

Why do you have wrong answers marked, it is very confusing. This one for example- the correct answer is A

Sathya235
Jan 4, 2022

None of the answer given is correct. The correct solution is document.getElementById("para").innerHTML+=rooms[i]+"<br>";

sirT0mci0
May 8, 2020

ignore my last comment. Answer B is correct.

ouzss
Oct 28, 2020

he said in new line so it is answer B