Functions
if-statements
Boolean Logic
Variables and Properties
Syntax
100

What is a function?

Functions hold code that tell objects what to do.

100

What are if-statements used for?

if-statements run lines of code only if a condition is true. The condition is a Boolean value (true or false).

100

Give the code (a Boolean expression) for the following:

The variable num is greater than or equal to 8.

num >= 8

100

What is a variable?

A variable holds a value. It like a box that can store a piece of information inside of it.

100

What symbol goes at the end of (almost) every line - excluding control structures?

; (semicolon)

200

Give the code for the following:

Call the function called moveX on the ball object. The speed parameter is 50.

ball.moveX(50);

200

How do you format an if-statement?

if (condition) {
    code;
}

200

What operator (symbol(s)) do you use to check if two values are equal?

== or ===

200

Give code for the following: 

Create a variable called num that equals 10.

var num = 10;

200

What is the format for calling a function?

objectName.functionName(parameters);

300

What is a parameter and where are they written in a function?

A parameter is an additional value used in a function, like the speed to move an object in the moveY function. Parameters are written inside the parentheses and separated by , (commas).

object.function(parameter1, parameter2);

300

If I want to run code when an if-statement condition is false, what kind of statement should I add to my if-statement?

An else statement.

if (condition) {
    code;
} else {
    code;
}

300

How do you write the and, or, and not operators? (Write the symbols.)

and: &&

or: ||

not: !

300

What is the difference between a variable and a property?

A variable is local and doesn't belong to an object.

A property is global and belongs to an object.

300

What is wrong with the syntax of this code?

var x = 10;
if (x == 10) {
x = 2;
}

The line x = 2; should be indented to look like:

var x = 10;
if (x == 10) {
    x = 2;
}

400

Give the code for the following:

Call the function called isTouching on the ball object. The parameter is the wall object.

ball.isTouching(wall);

400

Give pseudocode for this scenario:

If it's raining outside, I should take an umbrella with me. Otherwise, I'm going to wear flip-flops.

if (raining) {
    take an umbrella;
} else {
    wear flip-flops;
}

400

Give an example of a scenario where you would use a Boolean in code.

if-statement condition, while-loop condition, variable, etc.

400

If you want to have a score in your game, should you use a variable or a property?

Property

400

What is wrong with the syntax of this code?

if (ball.isTouching(wall)) {
    ball.moveY(10);

The if-statement is missing a closing { (curly brace).

500

Give the code for the following:

Set the x position of the ninja object to 400.

ninja.x(400);

500

Give the code for the following:

If the variable num is equal to 4, then set num equal to 1. Otherwise, if the variable num is equal to 1, then set num equal to 4.

if (num == 4) {
    num = 1;
} else if (num == 1) {
    num = 4;
}

500

Give the code (a Boolean expression) for the following:

The variable num is less than 5 AND the variable right equals true.

num < 5 && right === true

OR 

num < 5 && right

500

Give the code for the following: 

Create a property called direction that belongs to the ball object. Set it equal to 50.

ball.speed = 50;

500

What is wrong with the syntax of this code?

var rightPressed = isKeyPressed(Keys.rightArrow);
if (rightpressed) {
    ball.moveX(50);
}

The p in if (rightpressed) needs to be capitalized.