I'm struggling to create an array containing 5 random numbers ranging from 1 to 100. My goal is to then identify the even numbers and, for any odd ones, increase them by 1.
For instance:
array = [7, 13, 2, 60, 93]
The desired result should be
modified_array = [8, 14, 2, 60, 94]
, unfortunately I can't seem to figure it out..
Any assistance in solving this problem would be greatly appreciated. Thank you!
const array = []
const modified_array = []
while (array.length < 5) {
i = (Math.floor(Math.random() * 100) + 1);
array.push(i);
for (i in array);
if (i % 2 !== 0) {
modified_array.push(i)
}
}
console.log("array");
console.log(array);
console.log("-------------------------")
console.log("modified_array");
console.log(modified_array);