Skip to content

Instantly share code, notes, and snippets.

@opheliasdaisies
Created January 21, 2014 21:13
Show Gist options
  • Save opheliasdaisies/8548488 to your computer and use it in GitHub Desktop.
Save opheliasdaisies/8548488 to your computer and use it in GitHub Desktop.
questions for quiz 2
What does the following expression return?
4 > 1;
What does the following expression return?
"chatty" === "chatty";
What does the following expression return?
3 <= 300
Print the string "I just ate a lot" to the console.
if conditions will execute the code in the block if the boolean condition is true. What does the following expression print to the console?
if (5 === 5) { console.log("This code is executed") };
What does the following expression print to the console?
if (5 > 10) { console.log("Not so sure about this") };
What does the following expression print to the console?
if (5 > 10) {
console.log("Not so sure about this");
} else {
console.log("walking dead");
}
What does the following expression print to the console?
if ("candy" === 8) {
console.log("do something with your life");
} else if ("blah" === "blah") {
console.log("just chill, have fun");
} else {
console.log("people are strange");
}
What does the following expression print to the console?
if (5) { console.log("I like peanuts"); }
What doe the following expression print to the console?
if ("") {
console.log("program more");
} else if ("cool") {
console.log("party hard!");
} else {
console.log("blah");
}
What does the following expression return?
!false
What does the following expression print to the console?
if (!undefined) console.log("This syntax is weird…");
What does the following code print to the console?
var counter = 0;
while (counter < 3) {
console.log("The counter is at " + counter);
counter++
}
What does the following code print to the console?
var result = 0;
for (var i = 0; i < 5; i++) {
result += i;
}
console.log(result);
Arrays are ordered collections of elements. What does the following code print to the console?
var my_array = [1, "bob"];
console.log(my_array[1]);
What does the following code print to the console?
var q = "quack";
var num = 555666;
console.log([num, q, true]);
What does the following code print to the console?
["uno", "dos", "tres"].length;
Create an array with the following elements: "bob", 23, false.
Print the last element of my_array to the console.
var my_array = ["horse", "pig", "cow"];
What does the following code print to the console?
var writing_tools = ["pencil", "pen", "marker"];
console.log(writing_tools[writing_tools.length - 1]);
What does the following code print to the console?
var b = [1, 2];
b[0] = "master p";
console.log(b);
What does the following code print to the console?
var numbers = [2, 4, 6, 8];
var counter = 0;
var sum = 0;
while (counter < numbers.length) {
sum += numbers[counter];
counter++;
}
console.log(sum);
What does the following code print to the console?
var words = ["teenage", "mutant", "ninja", "turtles"];
var great_show = "";
for (var i = 0; i < words.length; i++) {
great_show += words[i] + " ";
}
console.log(great_show);
What does the following statement return?
typeof(["cats"]);
What does the following statement return?
[1, 89] === [1, 89];
What does the following code return?
var blue = ["da ba dee da ba die"];
blue === blue;
Sum all the elements in the following array if they are numbers, otherwise ignore the element. Print the result to the console.
var weird = [1, 40, "bob", [], false, 89];
var sum = 0;
for (var i = 0; i < weird.length; i++){
if (typeof(weird[i]) == 'number'){
sum = sum + weird[i];
}
}
Update the "shots" element in the following array to be "don't do it".
var beverages = ["beer", "wine", "shots"];
What are the falsey values in JavaScript? What does it mean when a value is falsey?
Concatenate all the elements in the following array that begin with the letter "b" and print the resulting sentence to the console.
var heaven = [34, [], "bodacious", "barbecues", "begin", "whatever", "by", "battering", true, "bacon"];
var str = "";
for (var i = 0; i < heaven.length; i++){
if (heaven[i][0] == "b"){
if (str.length == 0){
str = heaven[i];
} else {
str += " " + heaven[i];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment