1.7 Introduction to JavaScript Flashcards

(17 cards)

1
Q

Which part of a human is most similar to the role of JavaScript in a webpage?

A

dynamic behaviors like brushing teeth or jumping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where is the < script > element typically allowed to be placed within an HTML document?

A

in either the < head > or the < body > parts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which HTML attribute is essential for JavaScript to ‘find’ and manipulate a specific element on the page?

A

id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the JavaScript command document.getElementById(“red-btn”) do?

A

it searches the html document and returns a reference to the element with that specific ID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of a ‘variable’ in JavaScript, such as let redBtn?

A

to store a value or a reference to a webpage element for later use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which method is used to specify code that should execute only when a user interacts with a specific element, such as clicking a button?

A

addEventListener()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If you wanted to change the text color of a heading via JavaScript, which property would you update after selecting the element?

A

element.style.color = “blue”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When a webpage involves a complex game (like Tetris) or many hundreds of statements, what is the ‘good practice’ for organizing the JavaScript code?

A

putting the code in a separate file ending in .js and linking to it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of the <canvas> element in an interactive webpage?</canvas>

A

to create a rectangular area where javascript can draw graphics, lines, and shapes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define Javascript

A

A programming language that runs in the browser to enable webpage interactivity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define DOM

A

(Document Object Model)
The internal representation of the webpage that JavaScript “looks at” to find elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define if-else statement

A

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”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between an “inline” script and an “external” script file?

A

Inline scripts live inside < script> tags within your .html file. External scripts are separate .js files linked using the src attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is the id attribute so important for JavaScript developers?

A

Because an id must be unique on a page, it is the most reliable way for document.getElementById() to find exactly the right element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the specific steps a browser takes to change a heading’s color when a button is clicked?

A

The addEventListener detects the click -> it triggers a function -> the function uses the ID to locate the element -> the function updates the style property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a “void” element in HTML, and how does it differ from a <canvas> element?</canvas>

A

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>

17
Q

How would you write a JavaScript statement to change the background color of an element named box?

A

function changeBackgroundColor(newColor) {
let boxElement = document.getElementById(“box”);
boxElement.style.backgroundColor = newColor;
}