Any idea why this doesn't pass?

Any idea why this doesn't pass?
0

#1

Instructions:

Write function named createRange that will take a number and a default value and return an array of that many values

Example:

if you pass it 4 and "Hello" then it should return ["Hello", "Hello", "Hello", "Hello"]

My code:

function createRange(num, val) {
    let result = [];
    
    for(let i = 0; i < val.length; i++) {
        result.push(val);
    }
    
    
    
    return result;
};


#2
for(let i = 0; i < val.length; i++)

Describe, in plain English, what this should do.


#3

The problem exists in your for loop. I agree with @PortableStick’s comment asking you to put that code into plain language to see if anything jumps out. If it doesn’t, I’d suggest trying to add some console.log() messages within your for loop to see what the values are each instance/loop. That may point you to see that things aren’t evaluating as you intended.


#4

Thanks guys…this did it:

function createRange(num, val) {
    let result = [];
    
    for(let i = 0; i < num; i++) {
        result.push(val);
    }
    
    
    
    return result;
};