Defining elements.
The first thing in your code is that you should define an array as this:
var numbers = [];
In this array, you will handle every element you will receive from the prompt. So, with this said, you just need the total amount of numbers that you will use which can be retrieved by doing a prompt for a number:
var times = window.prompt("Insert number of numbers: ");
So, times would be our variable containing the amount of numbers we should ask the user, which will be saved on numbers.
Asking user for numbers X amount of times.
Now, what you could do is just a simple for loop which only job is to push the new number provided by the user:
for (let i = 0; i < times; i++) {
numbers.push(window.prompt(`Number ${i+1}: `))
}
This will give the user a prompt saying Number X:, which means the number that is being added.
Checking numbers for even and odds.
And for your functionality of giving a message when there is an even number in an odd index, you could do this:
numbers.forEach((n,i)=>{
if(n%2===0 && i%2!=0){
document.write(`Even number ${n} in odd position ${i} <br/>`);
}
});
Which will check every number you received from the user and check in one inline condition if even number is in odd position and will output the line only if this condition is true.
Printing the numbers.
And simply to output every number you can do:
numbers.forEach((n)=>{
document.write(n + "<br/>")
});
See how it works:
var times = window.prompt("Insert number of numbers"), numbers = [];
for (let i = 0; i < times; i++) {
numbers.push(window.prompt(`Number ${i+1}: `))
}
numbers.forEach((n,i)=>{
if(n%2===0 && i%2!=0){
document.write(`Even number ${n} in odd position ${i} <br/>`);
}
});
document.write("The numbers are: <br/>")
numbers.forEach((n)=>{
document.write(n + "<br/>")
});