programming with javascript coursera week 3 quiz answers

Knowledge check: Introduction to Functional Programming

1. What will print out when the following code runs?

var globalVar = 77;

function scopeTest() {
var localVar = 88;
}

console.log(localVar);

  • 77
  • 88
  • null
  • undefined

2. Variables declared using const can be reassigned.

  • true
  • false

3. When a function calls itself, this is known as _____________.

  • Recursion
  • Looping
  • Higher-order Function

4. What will print out when the following code runs?

function meal(animal) {
animal.food = animal.food + 10;
}

var dog = {
food: 10
};
meal(dog);
meal(dog);

console.log(dog.food);

  • 10
  • 20
  • 30
  • 40

5. What value will print out when the following code runs?

function two() {
return 2;
}

function one() {
return 1;
}

function calculate(initialValue, incrementValue) {
return initialValue() + incrementValue() + incrementValue();
}

console.log(calculate(two, one));

  • 1
  • 2
  • 3
  • 4

Knowledge check: Introduction to Object-Oriented Programming

6. What will print out when the following code runs?

class Cake {
constructor(lyr) {
this.layers = lyr + 1;
}
}

var result = new Cake(1);
console.log(result.layers);

  • 1
  • 2
  • 3
  • 4

7. When a class extends another class, this is called ____________.

  • Inheritance
  • Extension

8. What will print out when the following code runs?

class Animal {
constructor(lg) {
this.legs = lg;
}
}

class Dog extends Animal {
constructor() {
super(4);
}
}

var result = new Dog();
console.log(result.legs);

  • 0
  • undefined
  • null
  • 4

Shuffle Q/A 1

9. What will print out when the following code runs?

class Animal {

}

class Cat extends Animal {
constructor() {
super();
this.noise = "meow";
}
}

var result = new Animal();
console.log(result.noise);

  • undefined
  • null
  • “”
  • meow

10. What will print out when the following code runs?

class Person {
sayHello() {
console.log("Hello");
}
}

class Friend extends Person {
sayHello() {
console.log("Hey");
}
}

var result = new Friend();
result.sayHello();

  • Hello
  • Hey

Leave a Reply