Which part of a human is most similar to the role of JavaScript in a webpage?
dynamic behaviors like brushing teeth or jumping
Where is the < script > element typically allowed to be placed within an HTML document?
in either the < head > or the < body > parts
Which HTML attribute is essential for JavaScript to ‘find’ and manipulate a specific element on the page?
id
What does the JavaScript command document.getElementById(“red-btn”) do?
it searches the html document and returns a reference to the element with that specific ID
What is the purpose of a ‘variable’ in JavaScript, such as let redBtn?
to store a value or a reference to a webpage element for later use
Which method is used to specify code that should execute only when a user interacts with a specific element, such as clicking a button?
addEventListener()
If you wanted to change the text color of a heading via JavaScript, which property would you update after selecting the element?
element.style.color = “blue”;
When a webpage involves a complex game (like Tetris) or many hundreds of statements, what is the ‘good practice’ for organizing the JavaScript code?
putting the code in a separate file ending in .js and linking to it
What is the purpose of the <canvas> element in an interactive webpage?</canvas>
to create a rectangular area where javascript can draw graphics, lines, and shapes
Define Javascript
A programming language that runs in the browser to enable webpage interactivity.
Define DOM
(Document Object Model)
The internal representation of the webpage that JavaScript “looks at” to find elements.
Define if-else statement
A conditional block that allows the code to make decisions (e.g., “If the rating is 5, turn the stars gold; else, turn them gray”).
What is the difference between an “inline” script and an “external” script file?
Inline scripts live inside < script> tags within your .html file. External scripts are separate .js files linked using the src attribute.
Why is the id attribute so important for JavaScript developers?
Because an id must be unique on a page, it is the most reliable way for document.getElementById() to find exactly the right element.
What are the specific steps a browser takes to change a heading’s color when a button is clicked?
The addEventListener detects the click -> it triggers a function -> the function uses the ID to locate the element -> the function updates the style property.
What is a “void” element in HTML, and how does it differ from a <canvas> element?</canvas>
Void elements are “self-contained” (like <img></img> or <br></br>). The <canvas> is unique because it provides a blank pixel-grid that JavaScript can "paint" on dynamically.</canvas>
How would you write a JavaScript statement to change the background color of an element named box?
function changeBackgroundColor(newColor) {
let boxElement = document.getElementById(“box”);
boxElement.style.backgroundColor = newColor;
}