JavaScript – Introduction to Objects I – exercise 11 - SyntaxError: Invalid shorthand property initializer


#1

Hi,

I'm not sure I'm following protocol but unlike bigqueso I can't even get to 12, it keeps saying syntax error SyntaxError: Invalid shorthand property initializer. I have exactly the same code as below.

// help us make snoopy using literal notation
// Remember snoopy is a "beagle" and is 10 years old.
var snoopy = {
species: "beagle",
age: 10
};

// help make buddy using constructor notation
// buddy is a "golden retriever" and is 5 years old
var buddy = new Object();
buddy.species = "golden retriever";
buddy.age = 5;


[#322] JavaScript -- Introduction to Objects I -- exercise 11 -- passes but isn't getting a checkmark
#2

I've tried copy/pasting your code and I can not reproduce that error.

Could you try reloading/refreshing the web page?
If that doesn't work, try using the "Reset code" button.


#3

Hi, I've tried refreshing/reloading/resetting/logging out. Still doesn't work...Now I'm scared there's a stupid mistake in my code though I promise I've checked 50 times.

var snoopy = {
species = "beagle",
age = 10,
};

var buddy = new Object.();
buddy.species = "golden retriever";
buddy.age = 5;


#4

In the first post you have posted a correct code. In this comment your code has bugs. What's the reason?

  • in the literal notation we use colons;
  • there is no need to put a comma after the last key: value pair;
  • Object is a constructor, to call it you have to use Object().

Corrected code:

var snoopy = {
    species: "beagle",
    age: 10
};

var buddy = new Object();
buddy.species = "golden retriever";
buddy.age = 5;

#5

Ok, so the wrong comma is a mistake when I typed it in in my answer...and the rest...you have no idea how embarrassed I feel. I was on the metro thinking "the comma is a typo, it wasn't in my code when I logged it, so there still must be a problem". I think I should delete my account and reset everything under another name. And I still swear I checked 50 times. Thank a lot ...


#6

This topic was automatically closed after 7 days. New replies are no longer allowed.