Question

Given this array, write some JavaScript code that creates a new variable called "matchingAttendees" containing an...

Given this array, write some JavaScript code that creates a new variable called "matchingAttendees" containing an array with all attendees whose names start with an 'A' or a 'J'.

let attendees = [

["Jim", "Susan", "Emily", "Robert", "Carl"],

["Anthony", "Frank", "Hunter", "Colin", "Amanda"],

["Jenae", "Arthur", "Ronald", "Mary", "Rhonda"]

Homework Answers

Answer #1

Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code.  Please get back to me if you need any change in code. Else please upvote

CODE:

let attendees = [

["Jim", "Susan", "Emily", "Robert", "Carl"],

["Anthony", "Frank", "Hunter", "Colin", "Amanda"],

["Jenae", "Arthur", "Ronald", "Mary", "Rhonda"]]

let matchingAttendees = [] //creating an empty array to store name starts with A or J

for (index1 = 0; index1 < attendees.length; index1++) { //Loop through each array in attendees

    for (index2 = 0; index2 < attendees[index1].length; index2++) //Loop through each name in array

    {

        name = attendees[index1][index2]; //get the name in variable name

        if(name[0] == 'A' || name[0] == 'J'){ //Check if name starts with A or J

            matchingAttendees.push(name); //If yes, push to the array matchingAttendees

        }

    }  

}

print(matchingAttendees.toString()); //displaying the content of array matchingAttendees

OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions