Pages

Monday, August 29, 2016

JS recursive exercise 5

Write a recursive program to compute the exponent of a number:

8^3 = 8 * 8 * 8 = 512

This one is kind of easy, if you've finished the others.

You're just multiplying, 8 by all the other eights and returning the number.

Don't make this harder than it needs to be.

Once you've multiplied one eight, you've got one less exponent, etc...

1 comment:

  1. var exponent = function(number, exp){
    if(exp === 0){
    return 1;
    }
    return number * exponent(number, exp -1);
    }

    ReplyDelete