HTML Code Quiz

Quiz 6 8 questions

Prerequisites for the quiz

  1. HTML Code

Are you ready?

8 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
What is the purpose of the <samp> HTML element?
The <samp> element in HTML is used to represent sample output of a computer program. This goes with choice (C). For more info, refer to HTML Code: Sample output via <samp>.
Which of the following elements could be used to represent source code in an HTML document?
The <code> element is exclusively meant to denote source code in an HTML document. The rest of the given elements are used for different purposes. Hence, the correct choice is (C). For more info, refer to HTML Code: Code via <code>.

New to HTML, Alice has written the following HTML to showcase a block of code in an HTML document

<code>x = 10
print(x)</code>
What's the problem in her code?
Since Alice is trying to denote a 'block' of code (spanning multiple lines) in her HTML, it's desirable to have the <pre> element wrapping up the given <code> element. This is because <code> on its own is used to denote an inline piece of code. The correct choice is therefore (C). For more info, refer to HTML Code: Code via <code>.
On its own, the <code> element is meant to represent an inline piece of code. What does this mean?
This means that <code> shouldn't be used on its own to represent a 'block' of code (since it's an inline element in HTML), for if we need a block of code, we must wrap <code> with a <pre>. The correct choices are therefore (A) and (D). For more info, refer to HTML Code: Code via <code>.
Let's say we want to represent the textual output produced by some code in an HTML document. Which of the following HTML elements is the best choice to use?
The appropriate element to denote textual ouput of a piece of code in an HTML document is <samp>. This goes with choice (B). For more info, refer to HTML Code: Sample output via <samp>.
Which of the following definitions best applies to the <kbd> element?
Clearly it's the first choice — <kbd> is used to represent keyboard input. For more info, refer to HTML Code: Keyboard input via <kbd>.
The <kbd> and <code> elements can be used interchangeably. True or false?
False; <kbd> and <code> have quite different purposes. For more info, refer to HTML Code.

Bob wrote the following HTML for presenting a block of code and then the output text produced by that code?

<code>var x = 10;
console.log(x);
console.log(x + 10)</code>

<samp>10
20</samp>
How can his code be improved?
Both the <code> and <samp> elements in Bob's code are being used to represent 'blocks' of text, yet they are used alone; we should wrap up each of them with a <pre>. This is done in choice (D). For more info, refer to HTML Code.

"I created Codeguage to save you from falling into the same learning conundrums that I fell into."

— Bilal Adnan, Founder of Codeguage