00 var x = 3;
01 var y = 4;
02 x = x * 3 + (y - x);
What is x?
10
var myName = "Mrs. Nabors";
var myClass = "AP CSP";
console.log("Teacher: " + myname + "\nClass: " + MyClass);
myName and myClass have capitalization errors
This can hold one value at a time and can be referenced in expressions and commands like setProperty
A variable
00 var a = "fizz";
01 var b = "buzz";
02 a = "bizz";
03 b = a + b;
04 a = "fuzz";
05 a = b + a;
What is a?
bizzbuzzfuzz
var myName = "Mrs. Nabors";
var myClass = "AP CSP";
console.log("Teacher");
console.log("-----------");
console.log("myName");
myName should not be in quotes
This is a named set of commands that can be called repeatedly in a program
A function
if(age > 18 && GPA > 3.0){
write("You can have more than one release");
} else {
write("You need to select an additional elective");
}
What will the result be if age = 18 and GPA = 5.0?
"You need to select an additional elective"
var price = 6;
var money = 10;
var purchased = 2;
if(money - (price * purchased)){
write("You can buy this");
} else {
write("You don't have enough money to buy this");
}
money - (price * purchased)
does not evaluate to true or false
This is an expression that will evaluate to true or false
A Boolean expression
if(stamps == 10 || status = "employee"){
price = price * 0.50;
}
What will the result be if price = 13.00, status = "customer" and stamps = 10?
price = 6.50
/*only kids ages 5 - 12 are eligible for the Six Flags 600 minutes free ticket*/
if((age < 5) && (age > 12)){
write("You are not eligible for a ticket");
} else {
write("You are eligible for a ticket");
}
There are no numbers that are both smaller than 5 AND bigger than 12- it should be OR.
This is a conditional statement that provides a set of commands that will execute only when a specific Boolean expression evaluates to TRUE
if
Write the output for the following code.
function mystery(){
player1score = 10;
player2score = 6;
round = 1;
setProperty("scoreboard", "text", "Player 1: " + player1score + " Player 2: " + player2score + "\nRound " + round);
}
Player 1: 10 Player 2: 6
Round 1
console.log("If a chessboard were to have wheat placed upon each square such that one grain were placed on the first square, \ntwo on the second, four on the third, and so on, how many grains of wheat would be on the chessboard at the tenth square?");
var grain = 1; //first square
double();
double();
double();
double();
duoble();
double();
double();
double();
double(); //tenth square
console.log("We would have " + grain + " grains total.");
function double(){
grain = grain * 2;
}
sixth call to double is misspelled
This is a specific conditional statement that provides many different sets of commands. The computer will execute one set of command depending on the order of the Boolean expressions and which one is evaluated to be True first.
if-else-if
Describe the output of the following code if lives=0:
function idk(){
lives = lives - 1;
if(lives <= 0){
playSound("../wompWomp.mp3");
setScreen("gameOver");
} else {
setProperty("dialogue", "text", "Continue?");
}
}
}
It will play the sound and display the gameOver screen.
var newPhrase = "";
var a = "phrases";
var b = "clauses";
b = newPhrase;
a = "hooking up words";
console.log(newPhrase);
newPhrase = A + and + b;
console.log(newPhrase);
Variable A is capital and 'and' should be in quotation marks.
This can cause errors when the computer is not sure which variable to update based on what is most immediately accessible in the program
scope/local variables