0

i need help on this please

Function on power A and B without using **,raise typerror if input not int or float

20th Sep 2017, 3:14 PM
omoike sarah Igho
omoike sarah Igho - avatar
9 odpowiedzi
+ 1
Math.pow()
20th Sep 2017, 3:24 PM
Calviղ
Calviղ - avatar
+ 1
It's Math.pow(), not math.pow().
20th Sep 2017, 3:30 PM
Calviղ
Calviղ - avatar
+ 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 + " " "); }
20th Sep 2017, 3:34 PM
Calviղ
Calviղ - avatar
+ 1
Math.power(a,b) = 1 is a wrong statement. Math.pow() return a value.
20th Sep 2017, 3:38 PM
Calviղ
Calviղ - avatar
+ 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));
20th Sep 2017, 3:45 PM
Calviղ
Calviղ - avatar
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 + " " "); }
20th Sep 2017, 3:29 PM
omoike sarah Igho
omoike sarah Igho - avatar
0
Changed it ,same error
20th Sep 2017, 3:32 PM
omoike sarah Igho
omoike sarah Igho - avatar
0
Lemme try it out
20th Sep 2017, 3:36 PM
omoike sarah Igho
omoike sarah Igho - avatar
0
How about if I add initialize a an b ? I.e var a = 0; var b = 0;
20th Sep 2017, 3:38 PM
omoike sarah Igho
omoike sarah Igho - avatar