Question: Assignment is: Each element in the array will consist of the first name, space, the last name, space, and employee id, for example Hal Mortimer

Assignment is:

Each element in the array will consist of the first name, space, the last name, space, and employee id, for example "Hal Mortimer 12345". Your JavaScript code needs to split this single string into 3 parts, one for first name, one for last name, one for employee ID. Remember the string methods for IndexOf() and lastIndexOf() -- find the index of the first space to be able to splice out the first name; find the index of the last space to be able to splice out the employee ID; and use both of those space positions to splice out the last name. Do not include the spaces in any of the 3 pieces of data. Next, chop the data into the parts needed for the email address. Make sure the first and last names are all lowercase. Get the first letter of the first name. Get the first 7 letters of the last name -- if it is less than 7 letters, then use the whole last name. Get the first 2 digits of the employee ID. Put them together in the order of last name portion, first name letter, ID portion, then add "@company.com" at the end.

Work first on getting that logic to work on a single name, but keep in mind that you are going to process an array using a ForEach loop, so you will need a single callback function that will do all the work on each name in the array. It would be helpful to have one function that splits the string into its 3 parts, another function that extracts the necessary data from each part, and another function that calls those first 2 functions and then puts the pieces together into the email address.

So far I have..

let employee;

const str = ("Megan Berman", "John Wayne", "Peter Griffin", "Al Gore", "Cleveland Brown");

const employee_ID = ('1234','2345','5678','9216','5514');

var firstName = str.slice(str.indexOf(" ")+0, str.lastIndexOf(" ")-12);

var lastName = str.slice(str.indexOf(" ")-0, str.lastIndexOf(" ")-7)

var ID = employee_ID.slice(employee_ID.indexOf('')+0,employee_ID.lastIndexOf('')-2);

var fullName = str.slice(str.indexOf('')+0, str.lastIndexOf('')+1)

//function methods with 'this' keyword

const first = function(){

console.log('first name: ',this.firstName)

}

const last = function(){

console.log('Last Name: ', this.lastName)

}

const employId = function(){

console.log('employee id: ', this.ID)

}

const newEmail = function(){

console.log('New email address: ',this.firstName.toLowerCase()+ this.lastName.toLowerCase() +this.ID + '@company.com')

}

const full = function(){

console.log('full name: ', fullName)

}

console.log('Generating email addresses for employees')

first();

last();

employId();

newEmail();

full();

How would I do a string of names for the employee emails?

Assignment is: Each element in the array will consist of the first

Here is an example: Elements Console Sources Network Performance Memory This exercise generates email addresses using string processing and forEach loops. top Filter Default levels Generating email addresses data to process: Student Person 12345 get data: first name: Student, last name: Person, id: 12345 chop it: first name letter: s, last name group: person, id digits: 12 email: persons12@company.com data to process: Ann Adams 54321 get data: first name: Ann, last name: Adams, id: 54321 chop it: first name letter: a, last name group: adams, id digits: 54 email: adamsa54@company.com data to process: Ben Boardman 98765 get data: first name: Ben, last name: Boardman, id: 98765 chop it: first name letter: b, last name group: boardma, id digits: 98 email: boardmab98@company.com data to process: Carol Carlsen 56789 data: first name: Carol, last name: Carlsen, id: 56789 chop it: first name letter: C, last name group: carlsen, id digits: 56 email: carlsenc56@company.com

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!