Conditionals
Loops
Arrays
Functions
Miscellaneous
100
What is the "not equal" operator? Hint: The "equal" operator is ===
!==
100
What keyword can you use to immediately exit a while loop?
break
100
How can I get the number of elements in an array?

The length property. For example:


var a = [1, 7];
a.length;
100
What are the values in between the parentheses called? Hint: The correct answer is not HERE.

function someFunction (HERE) {
    // code
}
arguments (or parameters)
100
In a CSS selector, how could you target an element that has id="example"?

HERE {
   width: 40px;
}
#example
200
What will this print?

var x = 25;
if(x < 10) {
    console.log("first");
} else if (x > 10) {
    console.log("second");
} else if (x === 25) {
    console.log("third");
} else {
    console.log("fourth");
}
second
200
What will this print?

    var num = 0;
    var i = 0;
    while(i < 4){
        num = num + i;
        i++;
    }
    alert(num);
6
200
Define an array with 3 elements
[1, 7, 3]
200
Here I'm defining a new function. Write some code that calls it.

function callMe(value1, value2) {
    console.log("You passed in " + value1 + " and " + value2);
}
callMe(1, 2)
200
Give 2 ways to add 1 to num

   var num = Math.random();
   // Add 1 to num

num++

num = num + 1

num += 1

++num

300

What value could you set x to so "fourth" will be printed?

What value could you set x to so "third" will be printed?


if(x < 10) {
    console.log("first");
} else if (x > 10) {
    console.log("second");
} else if (x > 25) {
    console.log("third");
} else {
    console.log("fourth");
}
Setting x to 10 will print "fourth". There isn't a way to get "third" to print.
300
Here's a while loop. Which for loop will print the same thing as this while loop?

    var i = 0;
    while(i < 5) {
        i++;
        console.log(i);
    }

    A) for(var i = 0; i < 5; i++) {
        console.log(i);
       }

    B) for(var i = 0; i < 5; i++) {
        console.log(i);
        i++;
       }

    C) for(var i = 1; i < 6; i++) {
        console.log(i);
       }

    D) for(var i = 1; i < 5; i++) {
        console.log(i);
       }
C
300
Write some code that accesses the first element of this array.

   var school = ["Harlem", "Village", "Academy"];
   // Your code here
school[0]
300
The teacher will open this jsbin:

http://jsbin.com/aLoBoGaP/1/edit?js,console

What will get printed when I hit Run?

Nothing will get printed
300
Name the 3 different types we've learned so far.
  • Strings
  • Numbers
  • Booleans
400
What will this print?

   var x = 3;
   if(x === "3") {
      console.log("true");
   }else{
      console.log("false");
   }
false
400
Match first, second, and third with whatever letter best describes each.

    for(first; second; third) {
        // code
    }

    A) Gets run only once
    B) Gets run before each iteration of the loop
    C) Gets run after each iteration of the loop

first - A

second - B

third - C

400

True or False. Elements in an array must be the same type.

Reminder: The types we've learned so far are Strings, Numbers, and Booleans.

False
400
Define a function that takes no arguments and uses alert to print "hello".

function myFunc() {
   alert("hello");
}
400

Give 2 ways to comment out code.

Hint: One way comments out a single line, while the other way can be used to comment out multiple lines.


// This comments out one line of code

/* And this comments out
   multiples lines
   of code
*/
500
With conditionals, we're checking if something is true or false. We've learned 3 types so far in this class. What type is either true or false?
boolean
500
Write an infinite loop. You can use a for loop or a while loop.

while(true) { }

for(; true; ) { }

500
Name a function you can use to add an element to an array
push or splice
500
Write a line of code inside this function definition so the correct value (10) gets stored in the answer variable.

function add(num1, num2) {
    var sum = num1 + num2;
    // Add a line of code here
}

var answer = add(7, 3);
return sum;
500
What will this print?

var x = 1 + "2";
console.log(x);
12