<!DOCTYPE html>
<html lang="en">
<head>
<title>FuncFunc</title>
<script>
var newLine = function(str) {
var content = document.getElementById("content");
content.innerHTML = content.innerHTML + str + "<br/>";
};
var powers = function(p) {
var power = p;
return function(num) {
var ans = num;
for (var c = 0; c < (power-1); c++) {
ans = ans * num;
}
return ans;
};
};
var square = powers(2);
var cube = powers(3);
</script>
</head>
<body>
<div id="content"></div>
<script>
newLine(square(2));
newLine(square(3));
newLine(square(4));
newLine(cube(5));
</script>
</body>
</html>
Comments