Some questions not to do with fcc curriculum

hey guys,
I have finished es6 course, and moved to on to do regex.
I am excited, but wanted to check some of my new learned knowledge on a random quiz I have found online, got some questions wrong want some help on them if possible :slight_smile:

What would be the constructor of roger in the example below?

class Animal {
  constructor(noise) {
    this.noise = noise
  }

  speak() {
    console.log(this.noise)
  }
}

class Dog extends Animal {
  constructor(size) {
    super('bark!')

    this.size = size
  }
}

const roger = new Dog('large')

the lessons haven’t covered some of the stuff here so I briefly googled,
anyway the answer to the question is Dog , may anyone explain why not Animal? since it is the parent class. and dog uses extends

2nd question

Select the value of obj[123]

const obj = {

}

the choices were undefined or ‘party!’
answer is the latter , how come is ‘party!’? maybe the question is missing something?

Thanks if possible!

Hi, I don’t know much about classes, so I can’t help you with the first one. However, as you suspected, there is no way that second question can be right. If you don’t believe me, could you provide the link to the quiz so we can both check if I was right? Anyways, obviously, if you’re learning about classes, you already know this. But to reference a value in an object, it has to be defined. Since the constant has nothing defined within the object, obj[123] = undefined.

Tldr: Can’t help you with that first question, but the second one is wrong.

Every class has its own constructor, even if you don’t explicitly define one (in which case a default constructor will be provided for you).

Using the extends keyword to create a child class doesn’t change the fact that the Dog class has its own constructor.

1 Like

These concepts are covered in the Object Oriented section
You will learn about it in a few sections

1 Like

it seems wrong, but this is the quiz if you’re interested

The quiz is wrong. Any property that isn’t set is undefined.

const array = [1, 2, 3]
const extension = [4, 5, 6]

array = [...extension, ...array]

got another question, there reason array isn’t changed cause it is the wrong destructuring syntax, is that correct? ( can’t also redeclare array )

It’s because you can’t redeclare the array.

1 Like