12. Practice makes perfect


#1
var object1 = {
    name:"amartya",
    age: 24,
    location:"kolkata"
};
console.log(object1);
var object2 = {
    fruits:"banana",
    time: 05.50,
    location: "kolkata"
};
console.log("this is second" + " " + object3);
var object3 = {
    fruits:"grapes",
    time: 06.50,
    location: "kolkata"
};
console.log("This is third" + " " + object3);

Its not passing me .. Console saying

SyntaxError: Unexpected number

Please help with explanation...


#2

You probably get an error because in object2 and object3 you have time property that holds time, storing values without quotes JavaScript will interpret it as a number and that's invalid number format, so you have two choices:

Write your time values like this: 5.50 and 6.50
OR
wrap those values in single or double quotes in that way you can keep zeros at the beginning and your value will be treated as string.


#3

Thanks dude.. It worked.. Just removed the '0's from the beginning.. The values now look like 5.50 and 6.50.. :chocolate_bar: for you..


#4

I'm glad it helped :slightly_smiling:


#6

@codelearner5694

Hope you solved the problem.. But still am trying to explain your mistakes.

var object1 = {
    carName: "Honda";
    color: "Black";
};

In this object literal notation you used ';' but thats not allowed in this think literal notation as simple like this:

var object1 = {carName: "Honda" , color: "Black" };

In this case we use ',' as separator ..
Rest everything is fine Have fun mate..


#7

Yeah man, I found the mistake a few minutes later. Thanks though. Cheers!