Solution Review: Only Even

Let’s go over the solution for the challenge: Only Even.

We'll cover the following

Task

In this challenge, you were provided a list of integers. Using the list, you had to create and populate a new list. The final list could only consist of even multiples of 3.

Solution

Let’s go over the solution step-by-step.

The first thing you had to do was use a for-loop to multiply all the elements of integers with 3.

for(var i = 0; i<integers.length; i++){
  integers[i] = integers[i] * 3;
}

Next, you had to insert a nested if condition in the for-loop. This condition is for checking if the item in the current iteration is an even number. If it is an even number, add the item to the list evenList.

if(integers[i] % 2 == 0){
  evenList.add(integers[i]);
}

You can find the complete solution below:

You were required to write the code given from line 5 until line 9.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy