-2

Been having an issue with this and don't know where to start. I am programming this with JavaScript. How do I create an array containing the multiples of 4 between 20 and 800, inclusive?

Drafter
  • 21
  • 6
  • A good place to start is a loop. – VLAZ Jan 25 '21 at 07:51
  • 1
    Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output using the `[<>]` snippet editor. – mplungjan Jan 25 '21 at 07:52
  • 1
    Looks like an exercise question ahah. What did you tried where are you stuck and why ? – Alexis Jan 25 '21 at 07:52
  • Next time, try to provide some code snippet along with the question to avoid collecting negative votes. To find an answer chek the [Reminder operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder) (`%`) – Max Martynov Jan 25 '21 at 07:54
  • `const fillMult = (from,to,mult) => [...Array(to-from+1).keys()].map(i => i+from).filter(i => i%mult===0); console.log(fillMult(20,800,4))` – mplungjan Jan 25 '21 at 08:11

2 Answers2

1

Try this

let arr = [];
for(let i=20; i <= 800; i++) {
    if(i%4 === 0) {
        arr.push(i)    
    }
}
console.log(arr);

It will have all element which is multiple of 4 between 20 and 800

AkshayBandivadekar
  • 839
  • 10
  • 18
0

let array = [];

for(let i = 20; i <= 800; i++) {
  if(i % 4 == 0) {
    array.push(i);
   }
}

console.log(array);
Timothy Alexis Vass
  • 2,526
  • 2
  • 11
  • 30