Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The function should return an array of the first n multiples of the number x

function multiples(x, n) {
    let m = [];
    for (let i=1; i<= n; i++){
        x *= n[i];
        m.push(x);
    }
    return m;
    }

I don’t understand why my function is not working. I Need help please.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I think this is what you need.

 function multiples(x, n) {
  let m = [];
  for (let i=1; i<= n; i++){
      m.push(x*i);
  }
  return m;
}

The thing you were not achieving your desired output is due to the fact you are treating n as an array which is not. You just need to multiply the number x with i (which should be increasing until it becomes equal to n) and push it to the array.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading