Objective

Practise JavaScript String, Array and customized objects.

There are two parts in this assignment. You must work on both the parts in the same js file. Please comment before you start each part for instance, before part A type the following and so on.

/******************************
Part A
********************************/

Part A

Here, we will introduce you to the Mockaroo service: https://mockaroo.com

Need some mock data to test your app?
Mockaroo lets you generate up to 1,000 rows of realistic test data in CSV, JSON, SQL, and Excel formats.

Problem solved.

Use the image below for Field Name, Type and Options. Generate at least 10 rows of JSON data. see image.

Use the data for this part (A)

The data comes to your system as a standard download. Open it for editing. Copy it.

In your code, assign the JSON data as the value of a new variable as an array.

var people = // your pasted JSON goes here

Don't forget the statements trailing semicolon.

Now you have a rich body of data, with which you can do the standard get all, get one, add new, edit existing, and delete item tasks.

Step 1

Create a function named capNotFirstLetter using the function declaration syntax. The function receives a single parameter of String type. Update / change the first letter of the string to lower case and other letters to upper case. The function returns the updated String. Hint: use the property and methods of String object - length, substr(from, length), substring(from, to) , toUpperCase() and/or toLowerCase().

Step 2

Copy the array to a new array, with something like this:

var data = people.map(p => p);

Using the function written in Step 1, Update / change the first letter of the string to lower case and other letters to upper case for all FirstName objects of the array. Log the array in the console.

Step 3

Using the appropriate method, filter out objects with creditScore >400 and assign the data into a new variable. Log the new variable in the console. Do not use loop for this step.

Step 4

Sort the data array by date and log the sorted array in the console. Save your file as assignment2.js .

Part B

Start with comments like below in assignment2.js file after Part A code.

/******************************
Part B
********************************/
// an array of course objects
var courses = [
{ code: 'APC100', name: 'Applied Professional Communications', hours: 3, url:
'http://www.senecacollege.ca/' },
{ code: 'IPC144', name: 'Introduction to Programming Using C', hours: null, url: 'https://scs.senecac.on.ca/~ipc144/' },
{ code: 'ULI101', name: 'Introduction to Unix/Linux and the Internet', hours:
4, url: 'https://cs.senecac.on.ca/~fac/uli101/live/' },
{ code: 'IOS110', name: 'Introduction to Operating Systems Using Windows', hours: 4, url: 'https://cs.senecac.on.ca/~fac/ios110' },
{ code: 'EAC150', name: 'College English', hours: 3, url: null }
];
// prototype object for creating student objects
var student = {
name: "",
dob: new Date(),
sid: "",
program: "",
gpa: 4.0,
toString: function () {
return 'Student info for ' + this.name + ': born on ' + this.dob.toLocaleDateString() +', student id ' + this.sid + ', program ' + this.program + ', curre
nt GPA ' + this.gpa;
}
};

Type the above data for Part B in assignment2.js file that contains some given code, including an array (named courses) of course objects and a prototype object (named student) for creating student objects. Do not change the given code. Write your code beneath this given code and complete the following tasks:

Task 1:

  • Using appropriate array method, Remove the last course object form the given array courses and store the removed object to a variable.
  • Output a message to console to show the course which was removed from the array.
  • Create 4 course objects which should have the same properties as what the objects (in the course array) have. Store the 4 course objects in the variables ibc233, oop244, web222 and dbs201, and the object properties should have appropriate values.
  • Using appropriate array method, Add these course objects in the array courses.
  • Use for loop to loop through the course array in order to add the hours of the courses and log the total hours in the console.

Task 2:

  • Create 4 student objects based on the given prototype student. Give appropriate property values for all student objects.
  • Create an array named students and add all the student objects into the array.
  • Use the forEach method to iterate the array students and output the information of the student objects to the console.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.