Lesson_4
Practical Task #8
by Pavel_FD2
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./main.js"></script>
</body>
</html>
JavaScript
function pow(x, y) {
let arg = 1;
let frase = x + ' ^ ' + y + ' = ';
if (y == 1) {
return frase + x;
}
else if (y < 0) {
for (var i = y; i < 0; i++) {
arg /= x;
}
console.log(frase+arg);
}
else {
for (let i=0; i<y; i++){
arg *= x;
}
console.log(frase+arg);
}
}
const calculate = function(a) {
return function(sign) {
return function(b) {
switch(sign) {
case '+': console.log(a+' + '+ b + ' = ' + (a+b));
break;
case '-': console.log(a+' - '+ b + ' = ' + (a-b));
break;
case '*': console.log(a+' * '+ b + ' = ' + (a*b));
break;
case '/': if(b===0){console.log(a+' / '+ b + ' = ' + 'Ошибка (на ноль делить нельзя)')}
else console.log(a+' / '+ b + ' = ' + (a/b));
break;
};
};
};
};
console.log(pow(23,9));
console.log(calculate(6)('/')(3));