Homework 10

Question: Suppose you have the following code in JavaScript (recognize the data being passed to the variable in JSON format) - the var statement is just to declare the variable called friends

var friends = [{
     "name": "John",
     "age": "28",
     "gender": "male",
     "profession": "sales rep"
},
{
     "name": "Maryenne",
     "age": "26",
     "gender": "female",
     "profession": "web developer"
}];

Then, later in the program, that variable friends (that looks like an array, right?) is used to write some data in a table. So, if you see the following command in this same JavaScript code, that is referring to the above JSON structure, what will be the content of the variable tablecell1? Remember, the var statement is only declaring the tablecell1 variable!

var tablecell1 = '<tr><td>' + friends[0].name + '</td><td>' + friends[0].profession + '</td></tr>'

Answer: The content of tablecell1 would be the HTML to write a table row consisting of two columns. The content of the left cell would be "John" and the content of the right cel would be "sales rep".

Like this:

hw10.json