1

I'm trying to get into a bootcamp and this is a problem I'm clearly missing something on. I know I'm missing something obvious but I'm having trouble spotting it. Here's what I have so far:

function oddsUpTo(num) {
  let arr = [];
  for (let i = 1; i <= num; i += 2) {
    if (num[i] % 2 === 1) {
      arr.push(num[i]);
    }
  }
  return arr;
}
console.log(oddsUpTo(20)) // should equal[1,3,5,7,9,11,13,15,17,19]
Neo Anderson
  • 5,957
  • 2
  • 12
  • 29
kyle.nagel
  • 13
  • 2

1 Answers1

2

Your num is number not an array. Please try this way.

function oddsUpTo(num) {
    let arr = [];
    for (let i = 1; i <= num; i += 2) {
        arr.push(i);
    }
    return arr;
}
console.log(oddsUpTo(20));

Hope it works.

Rakesh Singh
  • 102
  • 1
  • 14