170k views
0 votes
print out the last even number from an array of integers, if there is no even number, then print out a sentence indicating so.

User Sahir
by
5.0k points

1 Answer

2 votes

Answer:

See the sample algorithm below.

Step-by-step explanation:

array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 22];

function last_even(arr) {

for( i = arr.length-1; i >= 0; i--) {

if (arr[i] % 2 == 0) {

console.log(arr[i]);

break;

}

else {

console.log("There is no even number!");

}

}

}

last_even(array);

print out the last even number from an array of integers, if there is no even number-example-1
User Idubnori
by
5.1k points