Can you give me working code?
Typically no one will provide you with the working code unless you provide the code you utilized and the error message you received. You have to get used to attempting it yourself if you truly want to learn. I’m learning that the hard way. But to assist, here is the correct code;
//Create the object called cashRegister
//and initialize its total property
var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
}
};
//Using dot notation change the total property
cashRegister.add(2.99);
Thanks…
i should start from beginning
Can I ask why we put add: function(itemCost){
this.total += itemCost;
}
Is there another way to do this or am I missing something ?
Is it because we have to add a method function in order to change add the new total? I am just not sure where you got item cost.
This may help you:
//Create the object called cashRegister
//and initialize its total property
var cashRegister={
total:0
};
//Using dot notation change the total property
cashRegister.total=2.99;
this part of the code that @dailydevelopment provided you with is in relation to task two.
*// Can I ask why we put *
add: function(itemCost){
this.total += itemCost;
}
I think @niloofarslvt has shown the simpler version for the first task in this lesson but you can always take note of the code kindly provided by @aledavila for when you make a start on the second task in the building a Cash Register lesson
this.total += itemCost;
is nothing but…
this.total = this.total + itemCost;