What function do you need to call to get the width of the screen?
getWidth()
Suppose we’ve written a function drawCircle that we want to call every time the mouse is clicked. How can we do this?
mouseClickMethod(drawCircle);
What keyword do you need to use to define a variable in JavaScript?
var
What function do you need to call to ask the user of the program to enter text?
readLine
What will the following code print to the screen?
println(2 + 2);
4
In the following code, we create a circle and add it to the screen. What is the meaning of the x variable?
var x = 20;
var circle = new Circle(x);
add(circle);
The radius of the circle
Suppose we’ve written a function drawCircle that we want to call every time a key is pressed. How can we do this?
keyDownMethod(drawCircle);
Which of the following variable names follows JavaScript conventions for best practices?
my_Name
myName
My_name
my name
myName
To ask the user of the program for a number, which function should you use?
readInt
readFloat
What will the following code output?
var x = 8 * 2 + 5 / 5;
println(x);
17
What are the coordinates of the top right corner of the screen?
getWidth(), 0
What is a callback function?
A function passed to an event handler that is called every time a certain event happens
Why do we use vars?
Variables are used to store information to be referenced and manipulated in a computer program.
They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves.
It is helpful to think of variables as containers that hold information.
What is the correct way to ask the user for a name and store it in a variable?
var name = readLine("Enter a name: ");
Evaluate the expression below. What will be printed?
var result = 5 * 2 + 8 / 4;
println(result);
12
Write the code to add a circle to the screen.
It should be blue, centered, and have a radius of 50
var circle = new Circle(50);
circle.setPosition(getWidth() / 2, getHeight() / 2);
circle.setColor(Color.blue);
add(circle);
Write the code to draw a square every time the mouse is clicked.
function start(){
mouseClickMethod(drawSquare);
}
function drawSquare(e){
var rect = new Rectangle(20,20);
rect.setPosition(0, 0);
add(rect);
}
Which of the following correctly declares and assigns a variable for the number of books you own?
a) var books = 5;
b) 5 = var books;
c) books == 5;
d) var books == 5;
var books = 5;
When a user enters ‘3’ for the following program, what will be printed?
var num = readInt("Enter a number: ");
var output = (num * num) - num;
println(output);
6
var remainder = 25 % 6;
println(remainder);
Write the code to add a circle to the screen.
Get the x and y position from the user's input
var x = readInt("Enter the x cord: ");
var y = readInt("Enter the y cord: ");
var circle = new Circle(10);
circle.setPosition(x, y);
add(circle);
write the code to add a circle to the screen every time the mouse is clicked.
position the circle where the mouse was clicked
function start() {
mouseClickMethod(drawCircle);
}
function drawCircle(e){
var circle = new Circle(20);
circle.setPosition(e.getX(), e.getY());
add(circle);
}
What will the following code output if the user inputs ‘James’ for the last name and ‘Bond’ for the first name?
var firstName = readLine("Enter first name: ");
var lastName = readLine("Enter last name: ");
println(firstName + " " + lastName);
Bond James
Write a function that asks the user for a number, squares it, and prints the result.
function squareNumber() {
var num = readInt("Enter a number: ");
var squared = num * num;
println("The square of " + num + " is " + squared);
}
How can we check if a number is even or odd?
Use the modulus operator