Created
August 23, 2018 13:45
-
-
Save alexandr-kazakov/b26ba8a58a22ce71bf225270ab56ab43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Возводит x в степень n (комментарий JSDoc) | |
* | |
* @param {number} x число, которое возводится в степень | |
* @param {number} n степень, должна быть целым числом больше 1 | |
* | |
* @return {number} x в степени n | |
*/ | |
function pow(x, n) { | |
var result = x; | |
for (var i = 1; i < n; i++) { | |
result *= x; | |
} | |
return result; | |
} | |
var x = prompt("x?", ''); | |
var n = prompt("n?", ''); | |
if (n <= 1) { | |
alert('Степень ' + n + | |
'не поддерживается, введите целую степень, большую 1' | |
); | |
} else { | |
alert( pow(x, n) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment