canvas
events
variables
user input
math
100

What function do you need to call to get the width of the screen?

getWidth()

100

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);

100

What keyword do you need to use to define a variable in JavaScript?

var

100

What function do you need to call to ask the user of the program to enter text?

readLine

100

What will the following code print to the screen?

println(2 + 2);

4

200

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

200

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);

200

Which of the following variable names follows JavaScript conventions for best practices?

my_Name

myName

My_name

my name

myName

200

To ask the user of the program for a number, which function should you use?

readInt

readFloat

200

What will the following code output?

var x = 8 * 2 + 5 / 5;

println(x);

17

300

What are the coordinates of the top right corner of the screen?

getWidth(), 0

300

What is a callback function?

A function passed to an event handler that is called every time a certain event happens

300

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.

300

What is the correct way to ask the user for a name and store it in a variable?

var name = readLine("Enter a name: ");

300

Evaluate the expression below. What will be printed?

var result = 5 * 2 + 8 / 4;

println(result);

12

400

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);

400

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);

}

400

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;

400

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

400

var remainder = 25 % 6;

println(remainder);

1
500

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);

500

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);

}

500

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

500

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);

}

500

How can we check if a number is even or odd?

Use the modulus operator