Khan JS Flashcards
(22 cards)
What function draws a rectangle in ProcessingJS?
rect(x, y, width, height)
How do you set the fill color to red?
fill(255, 0, 0)
What function sets the outline color of shapes?
stroke(r, g, b)
How do you declare a variable in JavaScript?
var x = 10;
What function is used to create animations by repeatedly executing code?
draw = function() {
};
What is the purpose of mouseX and mouseY?
They provide the current x and y coordinates of the mouse pointer.
How do you define a function in JavaScript?
var myFunction = function() {
code
};
What does an if statement do?
It executes code only if a specified condition is true.
How do you write an if-else statement?
if (condition) {
run code if true
} else {
another code if false
}
What is the syntax for a for loop?
for (var i = 0; i < 10; i++) {
// code
}
How do you create an array?
var myArray = [1, 2, 3];
How do you access the first element of an array?
myArray[0]
How do you define an object with properties?
var car = {
make: “Toyota”,
model: “Corolla”
};
How do you add a method to an object?
car.drive = function() {
// code
};
What is object inheritance?
It’s a way for one object to access the properties and methods of another object.
What function helps you print messages for debugging?
println(“message”);
Why are comments important in code?
They help explain what the code does, making it easier to understand and maintain.
How do you write a single-line comment in JavaScript?
// This is a comment
How do you display text on the canvas?
text(“Hello”, x, y);
How do you concatenate strings?
“Hello” + “ “ + “World”
How do you detect mouse clicks?
Use the mouseClicked() function.
What function checks if the mouse is pressed?
mouseIsPressed