2012-04-15 09:54:48Morris
[JavaScript] Understanding parameters
var area = function (w, l) {
// We should return the product of w and l.
return w*l;
};
var isDivisible = function (x, y) {
return x%y == 0;
};
var power = function (base, exponent) {
var result = 1;
for (var i = 0; i < exponent; i++) {
result = result * base;
}
return result;
};
power(2, 2);
var power = function(base, exponent) {
if(exponent == 0)
return 1;
return base * power(base, exponent-1);
};
console.log(power(2, 4) === 16);
console.log(power(3, 3) === 81);
console.log(power(5, 4) === 625);
// We should return the product of w and l.
return w*l;
};
var isDivisible = function (x, y) {
return x%y == 0;
};
var power = function (base, exponent) {
var result = 1;
for (var i = 0; i < exponent; i++) {
result = result * base;
}
return result;
};
power(2, 2);
var power = function(base, exponent) {
if(exponent == 0)
return 1;
return base * power(base, exponent-1);
};
console.log(power(2, 4) === 16);
console.log(power(3, 3) === 81);
console.log(power(5, 4) === 625);