183k views
1 vote
Agelist and gradelist contain information about students in a classroom. A programmer has already written the following code with that information. Var ages = [16,17,18, 17] var names = ["beni", "analise", "ricardo", "tanya"] var filterednames = []; which of the following programs will result in filterednames only containing the names of students who are 17 or older?

1 Answer

1 vote

Answer:

Step-by-step explanation:

To create a new array filterednames that only contains the names of students who are 17 or older, you can use a for loop and an if statement to iterate through the ages array and check the age of each student. If the age is 17 or older, you can add the corresponding name to the filterednames array using the push() method. Here is an example program that would achieve this:

var ages = [16, 17, 18, 17];

var names = ["beni", "analise", "ricardo", "tanya"];

var filterednames = [];

for (var i = 0; i < ages.length; i++) {

if (ages[i] >= 17) {

filterednames.push(names[i]);

}

}

After running this program, the filterednames array will contain the names "analise", "ricardo", and "tanya", since they are the students who are 17 or older.

User Bakir Jusufbegovic
by
7.0k points