Developsom
Coder
Hello everyone,
First of all; I have been coding since February now so as you can understand im a real beginner.
* For a school assignment I have to use a loop to multiply all the even and uneven numbers inside an array.
* The script must work even if the array contains a trillion numbers.
Down here you can see the script that I have written so far.
My small knowledge mind tells me that the script is complete and correct apart from the '///' lines.
However, nothing could be less true and maybe the problem lies somewhere else.
I have tried multiple ways since yesterday to add the multipliers into the '////' lines but nothing seems to work 🙁
Really, I don't want to get emotional or anything out here right but honestly my brain hurts. Can someone release me of this pain ?
This is one of my best tries.
However; to complete the assignment log must say;
My log after my best try says:
12 must be 8
10 must be 15
First of all; I have been coding since February now so as you can understand im a real beginner.
* For a school assignment I have to use a loop to multiply all the even and uneven numbers inside an array.
* The script must work even if the array contains a trillion numbers.
Down here you can see the script that I have written so far.
My small knowledge mind tells me that the script is complete and correct apart from the '///' lines.
However, nothing could be less true and maybe the problem lies somewhere else.
I have tried multiple ways since yesterday to add the multipliers into the '////' lines but nothing seems to work 🙁
Really, I don't want to get emotional or anything out here right but honestly my brain hurts. Can someone release me of this pain ?
Code:
const numbers = [2, 4, 5, 29, 38];
for (let i = 0; i < numbers.length; i++) {
if (i % 2 === 0) {
////---->MULTIPLY X2<------
} if ( i % 2 !== 0) {
////---->MULTIPLY X3<------
}
}
console.log(numbers)
This is one of my best tries.
Code:
const numbers = [2, 4, 5, 29, 38];
for (let i = 0; i < numbers.length; i++) {
if (i % 2 === 0) {
console.log(numbers[i] * 2)
} if ( i % 2 !== 0) {
console.log(numbers[i] * 3)
}
}
console.log(numbers)
However; to complete the assignment log must say;
4, 8, 15, 87, 76 ];
My log after my best try says:
4
12
10
87
76
12 must be 8
10 must be 15
Last edited: