1

I need to create a JSON object "bio" which contains a lot of variables in it:

var bio = {
"name": "my name",
"role": "Web Developer",
"contacts":
    {
        "mobile": "my phone",
        "email": "[email protected]",
        "github": "https://github.com/",
        "twitter": "https://twitter.com/",
        "location": "Los Angeles, CA"
    },
"welcomeMessage": "Welcome to my online resume.",
"skills": ["HTML5","CSS3","JavaScript","Bootstrap", "Angular", "CoffeeScript", "W3"],
"biopic": "http://placehold.it/150x150",
"display": displayFunc(){

}

};

When I try to run this with:

var formattedName = HTMLheaderName.replace('%data%', bio.name);
var formattedRole = HTMLheaderRole.replace('%data%', bio.role);

$('#header').prepend(formattedRole);
$('#header').prepend(formattedName);

Nothing happens. I believe the error is somewhere in the "contacts" variable because if I comment out contacts and everything below it the name and role show up. But if I comment out welcomeMessage and everything below that I still get nothing.

EDIT: For this class the contact variable is required to be:

contacts : an object with
      mobile: string
      email: string 
      github: string
      twitter: string (optional)
      location: string
5
  • 2
    That is not JSON. Errors in the (JavaScript) syntax it will show up as a Syntax Error in the Console Error Log. Not sure how bio.contacts is even "used" given the context.. Commented Jun 30, 2016 at 7:37
  • contacts is an array of objects. Not an object itself. Commented Jun 30, 2016 at 7:38
  • Notice that your displayFunc(){} needs to be function displayFunc(){} Commented Jun 30, 2016 at 7:40
  • That isn't JSON, JSON is a textural data format , see: What is the difference between JSON and Object Literal Notation? Commented Jun 30, 2016 at 7:41
  • @IvankaTodorova That was a mistake, I tried that after my first attempt didn't work, just pasted the wrong code here. I have "fixed" it now - in that my original non working code is in the post. Commented Jun 30, 2016 at 7:43

1 Answer 1

3

If you add function before displayFunc(){} then it should work (as @BubbleHacker mentioned)

Demo here: https://jsfiddle.net/mrLh3pz7/

var bio = {
"name": "my name",
"role": "Web Developer",
"contacts": [
    {
        "mobile": "my phone",
        "email": "[email protected]",
        "github": "https://github.com/",
        "twitter": "https://twitter.com/",
        "location": "Los Angeles, CA"
    }
],
"welcomeMessage": "Welcome to my online resume.",
"skills": ["HTML5","CSS3","JavaScript","Bootstrap", "Angular", "CoffeeScript", "W3"],
"biopic": "http://placehold.it/150x150",
"display": function displayFunc(){}
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.