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

Problem 1: Requirement # Requirements What is the value of a[5] in the array dec

ID: 3714426 • Letter: P

Question

Problem 1:


Requirement # Requirements


What is the value of a[5] in the array declared below:

var a = [2, 4, 6, 'Joe', 10, [1, 2], {lastName: 'Smith'}];


Problem 2:


Requirement # Requirements


var myQuote="He who laughs, lasts.";

Give the value of each of the following expressions:


a. myQuote.toUpperCase()


b. myQuote.indexOf("a")


c. myQuote.indexOf("@", 1)


d. myQuote.indexOf("who")


e. myQuote.indexOf("a", 10)


f. myQuote.lastIndexOf("a")


g. myQuote.lastIndexOf("a", 7)


h. myQuote.lastIndexOf("a", 10)


i. myQuote.charAt(7)


j. myQuote.charAt(myQuote.length)


k. myQuote.charAt(myQuote.length - 3)


Problem 3:


Requirement # Requirements


Explain the below code. Include the final output to console.log().


Tip: Higher Order Function (Callback).

function Thing(name) {

this.name = name;

}

Thing.prototype.doSomething = function(callback, salutation) {

callback.call(this, salutation);

}

function Afunction(salutation) {

console.log(salutation + " " + this.name);

}

var t = new Thing('John Smith');

t.doSomething(Afunction, 'Hello');


Problem 4:


Requirement # Requirements


What are the advantages of using Objects in JavaScript. Min 50 words


Submit Answer

Problem 5:


Requirement # Requirements


Create a an Object constructor function called MedRecord with the properties firstName, lastName, medRecord, medID, insuranceInfo.

Define a MedRecord prototype method called changeInsurance() that accepts the name of a patient new insurance information and update object insuranceInfo property.


Problem 6:


Requirement # Requirements


Put the below data in a JSON formatted array where each individual is its own object. Then write code that will print each person's first letter of their first name and last name (example: msmith)

firstName: Mike lastName: Smith

firstName: Anna lastName: House

firstName: Mark lastName: McDonald

Explanation / Answer

1:
Index starts with 0.
So, 5th index is the 6th element that is 1,2

Problem 2:
a. myQuote.toUpperCase() = HE WHO LAUGHS, LASTS.
Give the string in upper case.


b. myQuote.indexOf("a") = 8
The very first index when a is found in the given string.


c. myQuote.indexOf("@", 1) = -1
Not found in the string


d. myQuote.indexOf("who") = 3
The first time "Who" occured in the string is at index 3


e. myQuote.indexOf("a", 10) = 16
This gives the index of first occurence of 'a' in the string starting from 10th index


f. myQuote.lastIndexOf("a") = 16
The very last time a occured in the string is 16.


g. myQuote.lastIndexOf("a", 7) = -1
There is no existance of a till 7th index.


h. myQuote.lastIndexOf("a", 10) = 8
Checking in the string till the 10th index and gives the index of the last occurence of the character

i. myQuote.charAt(7) = l
7th index is the eighth character.


j. myQuote.charAt(myQuote.length) = Nothing
because the indices range from 0 to myQuote.length-1


k. myQuote.charAt(myQuote.length - 3) = t
3rd character from ending