Undefined help


#1


I don't know what's wrong. I'm trying to make a function that takes the power of a number but I get undefined instead of the result.


function power (base, exponent) {
        for (var k=0; k<exponent; k++) {
            var multiply=[];
            multiply.push(base);
        }

        for (var i=0; i<multiply.length; i++) {
            sum = 1;
            sum = sum * multiply[i];
        } 
}
console.log(power(2,3));


#2

You're printing the result of calling your function, but your function doesn't produce a result - so what you end up printing is undefined, because the result wasn't defined


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.