How would you create a variable called days and set it equal to 7?
var days = 7;
Is this code okay to use? If not, say why.
if ( teacher == "Mrs. Q" && period == 3 || 4 )
console.log("You are in AP CSP");
No.
Should say period==3 || period==4
What is output from this code if age is 15?
if ( age==16 )
console.log("You can drive!")
nothing
Name one reason for creating a function.
1) Naming a section of repeated code for reuse
2) Shortening your lines of code by reusing code
3) Easier to debug/edit when repeated code is encapsulated in one place
What is the assignment operator?
=
What's wrong with this code?
Variable score is initialized twice. Every time button2 is clicked, score is re-created, so it will never reach greater than 5.
I want to find the larger number between num1 and num2. What would replace missing code?
if ( <missing code> ) {
console.log( "num1 is bigger" );
else
console.log( "num2 is bigger" );
num1 > num2
What will be output from this code if you have 0 points?
if ( points > 0 ) {
console.log( "Keep Playing!" );
else
console.log( "Game Over" );
Game Over
You have a yellow triangle next to your code below. Why?
function myFunction() {
//lots of commands in here
}
You declared your function, but never called it.
What is the comparison operator for equality?
==
Naomi is trying to update the score of her game by 2 points. Here is her code. What is her mistake?
var score = 0;
score = 2;
Should be
score = score + 2;
I want to see if I qualify for the Sunday Student Discount. You get the discount if you're under 18 and if it's Sunday. What would be the Boolean condition?
My variables are age
& day
.
day == "Sunday" && age < 18
if ( age >= 65 )
console.log( "Senior Discount" );
else if ( age < 18 )
console.log( "Student Discount" );
else
console.log( "Regular Price" );
What is output if you are 18 years old?
Regular Price
Can you declare a function inside another function declaration?
No
What is the comparison operator for not equal?
!=
Cynthia is receiving an error. What is wrong with this code?
var points;
points = points + 1;
points is never initialized
Name a situation where this would be true.
( day == "Saturday" || day == "Sunday" ) && ( age < 18 )
If it's Saturday, and I'm 12 years old...then this situation would be true.
Find the error in logic.
if ( time > 12 )
console.log( "Afternoon" );
else if ( time > 22 )
console.log( "Bedtime" );
else
console.log( "Morning" );
The 2nd condition will never be done.
Can you call a function inside another function declaration?
Yes
What is it called when strings are added or "glued" together?
Concatenation