So I got this mathematical equation and I need to write it in pure JS using the Math object obviously.
I looked up at the docs about the required methods to solve it, but I get the NaN in the console when I output the result.
I suppose it's my stupid brain that cannot solve this correctly
Here's the code:
let
z = 5
, x = 10
, y = 2
, b = Math.cos(Math.pow(2)) * z Math.tan(2 * x) Math.abs(y)
;
console.log(b);
CodePudding user response:
prefer to use Exponentiation (**)
let
z = 5
, x = 10
, y = 2
, b = Math.cos(z)**2 Math.tan(2 * x) Math.abs(y)
;
console.log(b);
CodePudding user response:
You are using Math.pow()
incorrectly. The method takes two arguments, the base and the power.
I believe your expression b
should look like this:
b = Math.pow(Math.cos(z), 2) Math.tan(2 * x) Math.abs(y)