0
i need help on this please
Function on power A and B without using **,raise typerror if input not int or float
9 odpowiedzi
+ 1
Math.pow()
+ 1
It's Math.pow(), not math.pow().
+ 1
You need to convert input string to number.
var power = Number(prompt("input a"));
var power = Number(prompt("input b"));
//function for calculating power(a and b)
function power(a,b) {
if (b===0) {
Math.power(a,b) = 1;
} else {
return Math.power(a,b-1);
}
console.log("power is + " " ");
}
+ 1
Math.power(a,b) = 1
is a wrong statement.
Math.pow() return a value.
+ 1
Try this:
var a = Number(prompt("input a"));
var b = Number(prompt("input b"));
//function for calculating power(a and b)
function power(a,b) {
return Math.pow(a,b); // in fact, power function is redundancy function, since can be replaced by pow function.
}
console.log("power is " + power(a,b));
0
Here is my code snippet but it's returning 'undefined '
//Ask user for input
var power = prompt("input a");
var power = prompt("input b");
//function for calculating power(a and b)
function power(a,b) {
if (b===0) {
math.power(a,b) = 1;
} else {
return math.power(a,b-1);
}
console.log("power is + " " ");
}
0
Changed it ,same error
0
Lemme try it out
0
How about if I add initialize a an b ?
I.e var a = 0;
var b = 0;