Question 20
Back to Exercise
The page contains this HTML:
<div id="note" style="color: red;">Note</div>What does the following JavaScript code print when it runs on this page?
const note = document.getElementById("note");
note.style.fontSize = "18px";
note.style.width = 200; // a number, no unit
console.log(note.getAttribute("style"));
console.log(`[${note.style.width}]`, note.style.color);
- A color: red; font-size: 18px; width: 200px; [200px] red
- B color: red; font-size: 18px; [] red Correct
- C font-size: 18px; [] red
- D color: red; font-size: 18px; width: 200; [200] red
Correct Answer: Option B
style properties use camelCase and map to dashed CSS names. A length without a unit is invalid CSS, so width = 200 is silently ignored – write "200px".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!