I'm currently stuck on a math problem and could use some help. The task is to write a JavaScript function that identifies elements at even positions in an array. The array is composed of number elements. The desired result should be displayed in an element identified by the ID "result" as a text or string format. Here's an example: Input: [1, 2, 3, 4, 5, 6, 7, 8, 9] Output: 1 x 3 x 5 x 7 x 9 Below is the code I've written so far:
function evenPosition(arr) {
let evenIndexes = [];
let oddIndexes = [];
for (let i = 1; i < arr.length + 1; i++) {
if (i % 2 !== 0) {
oddIndexes.push(i)
} else {
evenIndexes.push(i)
}
}
}
evenPosition([1, 2, 3, 4, 5, 6, 7, 8, 9])
I'm having trouble getting the output in the desired format. If anyone could provide some guidance, I'd greatly appreciate it!