Assessment wanted for Test your skills: Object basics

Hi :wave: Could someone kindly check my work on Test your skills: Object basics?

I struggled especially working on 4, as I didn’t know how to add multiple object members (including a method!) to a constructor. :cold_sweat: I did a little bit of research and the result seems okay enough…?

Thank you in advance!

My work
Object basics 1

Object basics 2

Object basics 3

Object basics 4

Test page

Congratulations, @Risa

All tasks are correctly solved. In task 2 it may be better to use an array of objects for the albums. The keys (album1, album2) don’t really add anything meaningful.

Well researched. :sunglasses:
Those function constructors were mentioned at the end of “Introducing constructors”: JavaScript object basics - Learn web development | MDN. You will meet more of them later. Promised. :grin:

Have a nice day,
Michael

1 Like

Hi @mikoMK :wave:

Thank you so much!

I revised task 2 using an array of objects. Could you please see if I did correctly?

I think I struggled to understand how to use multiple objects from the example written in “Introducing constructors”, because it only uses one object createPerson(name) {} :sweat_smile:

Anyway I’m happy that I understand it correctly now! Hopefully I get used to them when I meet them more in the future! :blush:

Thank you!
Risa

1 Like

This looks better now :+1:

The first example is indeed some kind of “in between” version, but the second example further down shows a real constructor:

function Person(name) {
  this.name = name;
  this.introduceSelf = function() {
    console.log(`Hi! I'm ${this.name}.`);
  }
}

where you then create two objects with the new keyword:

const salva = new Person('Salva');
salva.name;
salva.introduceSelf();

const frankie = new Person('Frankie');
frankie.name;
frankie.introduceSelf();

This is comparable to the cats in the task.

1 Like

Hi @mikoMK,

I think I understand constructors much better now!

Thank you for always being so helpful! :blush:

1 Like