Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JavaScript/JSON Exercise 1 Creating an JavaScript Object Create an object called person with name = John, age = 50. Then, access the object to display

JavaScript/JSON

Exercise 1 Creating an JavaScript Object

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.

Display the result here.

After you finish coding, save it as exercise-6-1.html and FTP the code to your apollo server [20 pts]

Answer:

Exercise 2 JSON Syntax

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:

"param1":"value1", "param2":"value2", ...

You task here is:

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

Parameter

Value

firstname

John

lastname

Doe

memberStatus

Full

Answer:

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

alert(jsonObject.param1);

Now, edit the JSON object detailed in the code to include an additional parameter city with 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 of clubMember.city. [10 pts]

Answer:

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

Answer:

Exercise 3 JSON parse()

You can interpret a JSON string using the method JSON.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.

var Mary = '{ "height":5.2, "age":36, "eyeColor":"brown"}';

// use JSON.parse() to create an object 'objectMary':

var objectMary = JSON.parse(Mary);

You task here is:

1)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]

Answer:

Exercise 4 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:

1)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]

2)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 display should look like this:

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]

Answer:

Exercise 5 JSON Simulating Associative Arrays

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

var myArray = [];

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.

var meeting = {

"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']'

1)You need to add a line of code to make sure meeting's end day to display. [5 pts]

Answer:

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

Answer:

Grading rubric for Each Problem

Exercise 1 [20 points]

Exercise 2 [30 points]

Exercise 3 [15 points]

Exercise 4 [25 points]

Exercise 5 [10 points]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions