var pow = function(x, n) { for (var i = 2; i <= n; i++) { x *= x; } return x; }; var x = prompt('x?', 4); var n = prompt('n?', 2); alert(pow(x, n));