Last Name: Johnson
First Name: Scott J
City: Detroit
1) Using the const key word create two arrays, with the variable names ‘oddArray’ and ‘evenArray’.
a. Use this ‘oddArray’, [‘5’, ‘7’. ‘1’, ‘3’], for your assignment.
b. Use this as your ‘evenArray’, [‘0’, ‘6’. ‘4’, ‘2’], for your assignment.
2) You will create an object with a variable name called ‘initialObj’. Inside this object you will assign three attributes (key-value pairs).
a. One of the attributes will be called ‘city’, the value for this attribute is shown in the webphone data under the city.
b. Next attribute will be called ‘name’, the value for this attribute will be the concatenation of what is shown under first name and last name in webphone. If there is middle initial in the name include that as well. For example if first and last name is only present the value will be “John Doe” (with a space between first and last name). If there is a middle initial in the webphone, the value will be “John J Doe” (space between first name and middle initial, and a space between middle initial and last name).
c. Next attribute will be called ‘defaultValue’. Set its value to number 2.
3) Next, you will create a variable called ‘numberOfNames’ in which you will assign number of names that is in the name attribute of the initialObj. For example, if my name consists of ‘Jeswin Abraham’, the value will be 2, if my name contains ‘Jeswin J Abraham’, the value will be 3. This must be done dynamically and programmatically. Hardcoded values will not be accepted.
4) Then, you will create a constant variable called ‘cityLength’ that stores the length of the characters of the city attribute in the initialObj.
5) Next, create a constant variable called ‘index’. Its value will be ‘cityLength’ divided by ‘numberOfNames’ rounded to the nearest integer.
6) Using the variable ‘cityLength’, determine if the integer is an odd number or even number.
7) Create a const variable called ‘parityOfCity’, and assign the value ‘odd’ or ‘even’ based on the value found in step 6.
8) Create a variable called ‘result’.
a. Its value would be set by using the value of ‘index’ to access the element of the appropriate array.
b. The appropriate array will be determined by the value of ‘parityOfCity’.
c. If the index value is greater than the length of the array, then programmatically default to the last element of the array.
9) Now create an object called ‘finalObj’, and assign the values of initialObj to the final Obj.
10) Modify the ‘defaultValue’ in the finalObj by adding the values of ‘defaultValue’, and ‘result’. For example, if my ‘defaultValue’ variable is 2, and my ‘result’ variable is ‘7’, the combined value will be 9 (2 + 7).
11) Now write a console.log statement for both the ‘initalObj’ and ‘finalObj’.
12) If the finalObj.combinedValue and initalObj.value have the same values, then the solution is incorrect. The initialObj must preserve its initial values, only the finalObj will have the new concatenated values.