CodeHS Web Development Accreditations 1 — Questions and Answers
Question 1: Which HTML tag is used to link an external CSS file to an HTML document?
- style
- link (Correct answer)
- css
- script
Correct answer: link
The `<link>` HTML tag is specifically designed to create relationships between the current document and an external resource, most commonly an external stylesheet. When used with `rel="stylesheet"` and `href="path/to/style.css"` attributes, it tells the browser to apply the styles defined in the linked CSS file to the HTML document. This separation of concerns improves code organization and reusability.
Question 2: Which JavaScript function is used to select an element by its ID?
- document.getElementById() (Correct answer)
- document.querySelector()
- getElementByClass()
- selectElement()
Correct answer: document.getElementById()
The `document.getElementById()` JavaScript function is a fundamental method for interacting with the Document Object Model (DOM). It allows developers to retrieve a reference to an HTML element by its unique `id` attribute. This function is widely used to manipulate specific elements, such as changing their content, style, or adding event listeners, making dynamic web pages possible.
Question 3: Which CSS property is used to change the font size of text?
- font-size (Correct answer)
- text-size
- font-style
- text-font
Correct answer: font-size
The `font-size` CSS property is used to control the size of the text within an HTML element. It accepts various units like pixels (px), ems (em), rems (rem), or percentages (%). Adjusting this property allows designers to ensure readability and create visual hierarchy in web content, making it a core aspect of typography in web design.
Question 4: Which HTML element is used to create an ordered list?
- ol (Correct answer)
- ul
- li
- dl
Correct answer: ol
The `<ol>` HTML element is used to create an ordered list, where each list item is numbered sequentially. This is ideal for presenting steps, rankings, or any sequence where the order of items is significant. Each individual item within the ordered list is defined using the `<li>` (list item) tag.
Question 5: Which of the following is used in JavaScript to handle asynchronous operations?
- for loop
- setTimeout()
- async and await (Correct answer)
- return
Correct answer: async and await
In JavaScript, `async` and `await` are keywords introduced to simplify working with asynchronous operations, particularly Promises. The `async` keyword declares a function as asynchronous, allowing it to use `await` inside. `await` pauses the execution of the `async` function until a Promise settles (resolves or rejects), making asynchronous code appear and behave more like synchronous code, improving readability and error handling.
Which HTML tag is used to link an external CSS file to an HTML document?