Yo guys! Anyone know what is wrong with this? Build a Cash Register


#1

//Create the object called cashRegister
//and initialize its total property
var cashRegister = new Object {
this.total = 0
};

//Using dot notation change the total property
cashRegister.total = 2.99;


#2

Could you add the "Error" your receiving as well as any instructions for the lesson?


#3

@lolman it is saying there is a syntax error saying "SyntaxError: Expected ' : ' :sunglasses:


#4

oh sry @lolman its saying it expects a semicolon not a colon


#5

and no this


#6

Correct, so instead of using "this.total = 0" there is another way to do it.

total : 0

The reason that you would use "this.variable = 'value'" would be if the variable was already created and being called in a function or something.

However, when initializing a variable inside of an object, you will just replace the " = " with " : ". Meaning it is a local variable to that specific object.


#7

oh right oops that was stupid :joy:


#8

@lolman but it doesn't work!

//Create the object called cashRegister
//and initialize its total property
var cashRegister = new Object() {
total: 0
};

//Using dot notation change the total property
cashRegister.total = 2.99;


#9

never mind guys I found out my problem. I was using the Object contructor and the literal notation at the same time for some reason