Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Create an object called person with name = John, age = 50.Then, access the obj

ID: 3586877 • Letter: 1

Question

1.Create an object called person with name = John, age = 50.Then, access the object to display "John is 50 years old”. I have written some code here.

Hint: Create an object with the var keyword, followed by a name and an "=" sign.
Put the properties and values inside the {}; signs

Note: Use getElementById() and innerHTML to display your output.

</html>

<html>

<body>

<p id="demo">Display the result here.</p>

<script>

// Create the object here

</script>

</body>

</html>

After you finish coding, save it as exercise-6-1.html

2.JSON data is expressed as a sequence of parameter and value pairs, each pair using a colon character to separate parameter from value. These "parameter":"value" pairs are themselves separated by commas. The whole sequence is enclosed in curly braces to form a JSON object representing your data. Here is the syntax rule:

You task here is:

Create a JSON object called clubMember. The object should contain the following information. [15 pts]

Parameter

Value

firstname

John

lastname

Doe

memberStatus

Full

Answer:

Objects written in JSON notation can have their properties accessed directly using the usual dot notation in this way:

Now, edit the JSON object detailed in the code to include an additional parametercitywith an appropriate value of your choice. For example, you live in Raleigh, then use Raleigh.

Add an additional statement after the object definition to output the value ofclubMember.city.[10 pts]

Answer:

After you finish the above coding, add some additional necessary html code save it as exercise-6-2.html. Write down your link below. [5 pts]

Exercise3 – JSON parse()

You can interpret a JSON string using the methodJSON.parse(), which takes a string containing a JSON-serialized object and breaks it up, creating an object with properties corresponding to the "parameter":"value" pairs found in the string.

You task here is:

Add an additional line after the existing code to log the value of Mary's age to the console. [10 pts]

Answer:

Add some additional necessary html code save it as exercise-6-3.html and FTP the code to your apollo server. Write down your link below. [5 pts]

Exercise4 – JSON stringify()

You can create a JSON-encoded string of an object using the JSON.stringify() method.

Such string-encoded objects are useful when, for instance, you want to transmit object data across a communications network; your object can be sent as a string and reconstructed at the other end.

You task here is:

A file called exercise-6-4.html is available at: http://apollo.waketech.edu/~frank/dba130/lesson6/. You will see nothing when you click on the exercise-6-4.html. But the code is there. At the link page, you need to view source. Copy the source and paste the source below. [10 pts]

html>

<body>

<script>

var frank = '{"height":5.7, "age":40, "eyecolor":"brown"}';

var myObject = JSON.parse(frank);

var out ="";

for (i in myObject) {

    out += i + " = " + myObject[i] + " ";

}

alert(out);

</script>

</body>

</html>

Add an additional line after the existing code to output the value of Mary's information to the web browser. [10 pts]

your web output should like this

{"height":5.2,"age":36,"eyecolor":"brown"}

Answer:

Add some additional necessary html code save it as exercise-6-3.html . Write down your link below. [5 pts]

Answer:

Exercise5 – JSON Simulating Associative Arrays

You may recall that the elements in JavaScript arrays have unique numeric identifiers.

varmyArray = [];

myArray[0] = 'Monday';

myArray[1] = 'Tuesday';

myArray[3] = 'Wednesday';

In many other programming languages, you can use textual keys to make arrays more descriptive:

myArray['startDay'] = 'Monday';

In the lecture, we know that JavaScript does not directly support so-called associative arrays, but we can to some extent simulate their behavior by using JSON notation.

You task here is:

Take a look at the meeting object listed in the code.

varmeeting = {

   "startDay" : "Monday",

   "nextDay" : "Tuesday",

   "endDay" : "Wednesday"

};

You can access the individual properties of the object as if they were elements in an associative array:

'meeting['startDay']'

You need to add a line of code to make suremeeting's end dayto display.[5 pts]

Along with the code added, create an HTML file called exercise6-5.html and uploaded it to your apollo server. [5 pts]

Answer:

</html>

<html>

<body>

<p id="demo">Display the result here.</p>

<script>

// Create the object here

</script>

</body>

</html>

Explanation / Answer

6.1 java scripty object
<html>
<html>
<body>
<h2>display the result of java script object</h2>
<p id="demo">Display the result here</p>
<script>
var person = {firstName:"John", lastName:"Doe", age:50};
document.getElementById("demo").innerHTML =
person.firstName + " is " + person.age + " years old.";
</script>
</body>
</html>


6.2 JSON OBJECT
<html>
<html>
<body>
<p>json object</p>
<p id="demo"></p>
<script>
var clubMember = { "firstName":"John", "lastName":"Doe", "memberStatus":"full"};
for (x in clubMember) {
    document.getElementById("demo").innerHTML += clubMember[x] + "<br>";
}
</script>
</body>
</html>

6.2 b)to add additional statement
<html>
<body>
<p>Access a JSON object to add additional statement </p>
<p id="demo"></p>
<script>
var clubMember = { "firstName":"John", "lastName":"Doe", "memberStatus":"full","city":"Raleigh"};
document.getElementById("demo").innerHTML += clubMember.city + "<br>";
</script>
</body>
</html>

6.3 JSON.parse()
<html>
<body>
<h2>using JSON parse</h2>
<p id="demo"></p>
<script>
var mary = '{ "height":5.2, "age":36, "eyeColor":"brown"}';
var objectMary = JSON.parse(mary);
document.getElementById("demo").innerHTML = objectMary.age;
</script>
</body>
</html>

6.4 Json.stringyfy()

<html>
<body>
<h2>Create JSON using stringify.</h2>
<p id="demo"></p>
<script>
var mary = {"height":5.2,"age":36,"eyecolor":"brown"}
var myJSON = JSON.stringify(mary);
document.getElementById("demo").innerHTML = myJSON;
</script>
</body>
</html>