Khan JS Flashcards

(22 cards)

1
Q

What function draws a rectangle in ProcessingJS?

A

rect(x, y, width, height)

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

How do you set the fill color to red?

A

fill(255, 0, 0)

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

What function sets the outline color of shapes?

A

stroke(r, g, b)

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

How do you declare a variable in JavaScript?

A

var x = 10;

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

What function is used to create animations by repeatedly executing code?

A

draw = function() {

};

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

What is the purpose of mouseX and mouseY?

A

They provide the current x and y coordinates of the mouse pointer.

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

How do you define a function in JavaScript?

A

var myFunction = function() {
code
};

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

What does an if statement do?

A

It executes code only if a specified condition is true.

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

How do you write an if-else statement?

A

if (condition) {
run code if true
} else {
another code if false
}

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

What is the syntax for a for loop?

A

for (var i = 0; i < 10; i++) {
// code
}

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

How do you create an array?

A

var myArray = [1, 2, 3];

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

How do you access the first element of an array?

A

myArray[0]

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

How do you define an object with properties?

A

var car = {
make: “Toyota”,
model: “Corolla”
};

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

How do you add a method to an object?

A

car.drive = function() {
// code
};

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

What is object inheritance?

A

It’s a way for one object to access the properties and methods of another object.

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

What function helps you print messages for debugging?

A

println(“message”);

17
Q

Why are comments important in code?

A

They help explain what the code does, making it easier to understand and maintain.

18
Q

How do you write a single-line comment in JavaScript?

A

// This is a comment

19
Q

How do you display text on the canvas?

A

text(“Hello”, x, y);

20
Q

How do you concatenate strings?

A

“Hello” + “ “ + “World”

21
Q

How do you detect mouse clicks?

A

Use the mouseClicked() function.

22
Q

What function checks if the mouse is pressed?

A

mouseIsPressed