Skip to content

Instantly share code, notes, and snippets.

@tessafallon
Last active January 4, 2016 04:19
Show Gist options
  • Save tessafallon/8567372 to your computer and use it in GitHub Desktop.
Save tessafallon/8567372 to your computer and use it in GitHub Desktop.
JS quiz 4
1. var person = {
name: "Joe Camel",
age: 42,
status: "dead"
}
console.log(typeof person);
ANSWER: Object
2. var hat = {
size: "large",
color: "orange"
}
console.log(hat.size);
ANSWER: large
3. var teddy_bear = {
texture: "fluffy"
}
console.log(teddy_bear["texture"]);
ANSWER: error [wrong]
4. var fat_joe = {
crew: "Terror Squad"
}
fat_joe.crew = "something";
console.log(fat_joe.crew);
ANSWER: Terror squad [wrong]
5. var pen = {};
pen.ink = "blue";
console.log(pen.ink);
ANSWER: blue
6. What does the following code print to the console?
var walking_dead = {
topic: "zombie apocalypse"
}
console.log(walking_dead["main_character"]);
ANSWER: undefined
7. var bottle = {
contents: function () { return "some fine bubbly" },
color: "green"
}
console.log(bottle.contents());
ANSWER: some fine bubbly, green [wrong]
8. var yao = {
self: function () { return this }
}
console.log(yao === yao.self());
ANSWER: true
9. var lebron = {
occupation: "basketball",
introduction: function () {
return "My name is LeBron and I play " + this.occupation
}
}
lebron.introduction();
ANSWER: "My name is LeBron and I play basketball"
10. var square = {
side_length: 4,
area: function () {
return this.side_length * this.side_length;
}
}
console.log(square.area());
ANSWER: 16
11. var me = {
first_name: "Matthew",
last_name: "Powers",
full_name: function () {
return this.first_name + " " + this.last_name;
}
}
console.log(me.full_name());
ANSWER: "Matthew Powers"
12. var mug = {
capacity: "10 fluid ounces",
customer_message: function (desired_size) {
if (desired_size > 10) { return "This mug is not large enough for you" };
}
}
console.log(customer_message(13));
ANSWER: you need to call mug.customer_message(13)
13. function global_function () { return "I can be called anywhere" };
var an_obj = {
something: global_function
}
console.log(an_obj.something());
ANSWER: "I can be called anywhere"
14. var person = {
age: 32,
address: {
city: "New York",
state: "NY"
}
}
console.log(person.address.city);
ANSWER: "New York"
15. var golf = {
type: "sport",
clubs: {
high_end: "taylor made",
low_end: "rusty basement clubs"
}
}
golf.clubs.high_end = "callaway";
console.log(golf.clubs.high_end);
ANSWER: callaway
16. var ideal_scene = {
status: "chillin'",
location: "somewhere with good waves",
thoughts: "bling bling"
}
delete ideal_scene.thoughts
console.log(ideal_scene.thoughts);
ANSWER = undefined [wrong]
17. var zombie = new Object();
zombie inherits the attributes of object
18.
var game = { title: "tic tac toe" };
var same_game = { title: "tic tac toe" };
console.log(game === same_game );
ANSWER = false
19. var lyric = { lyric: "right now, aight" };
console.log(lyric === lyric);
ANSWER: true
20. var ruff_ryders = {
dmx: {
birthplace: "Mount Vernon, NY"
}
}
console.log(ruff_ryders.lox.birthplace);
ANSWER: error
21. var ruff_ryders = {
dmx: {
birthplace: "Mount Vernon, NY"
}
}
console.log(ruff_ryders.lox && ruff_ryders.lox.birthplace);
ANSWER: Same error as above [not entirely correct]
22. var a = {
x: "y"
}
console.log("x" in a);
ANSWER: "y" [wrong]
23. var abc = {
zz: "ll"
}
console.log(abc.hasOwnProperty("zz"));
ANSWER: "ll" [wrong]
24. var dmx = {
occupation: "rapper"
real_name: "Earl Simmons";
}
25. var circle = {
radius: 10
}
SCORE: 18/25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment