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
********************************/
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 .
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:
Task 2: