+ 2
Javascript Math question
Hello guys. var x = 2; var y = Math.sqrt(Math.pow(x,4),2); Alert(y) Can someone explain please
13 ответов
+ 1
I just ran the code several times and had to change alert to document.write but that shouldnt affect the outcome.
the ,3 didn’t seem to factor into the calculation at all. didn’t matter if I changed to 5 or deleted it alltogether...
x = Math.sqrt(16,3,5,102846728)
document.write(x)
#output is still 4
+ 3
you are welcome. thanks for sticking with me :)
+ 2
I am no expert but I suspect it means
do the x so 2 to the power of 4 so 16, and then do 16 with a root 2
so it is Math.sqrt(16,2) but the 16 has been replaced with a function which results in 16
I mean the 16 is replaced with Math.pow(x,4)
+ 2
Its kinda weird. I thought it was able to use sqrt with only one number and not with two like in this example (16, 2)
+ 2
Wow, that was very tricky hahaha. Thank you a lot for your time and help! Appreciate it
0
Also:
var x =
Math.pow(Math.floor(Math.sqrt(4)),2)
alert(x)
0
These 2 questions were in JS challenge, i put 2 as a result, thinking it is true, but 4 is the right answer
0
so yeah, if the answer was 4 then my explanation pans out :)
0
Alright but what if, for example number 3 would have been put instead of number 2? How would you calculate that
0
which 2 do you want to substitute?
0
Var y = Math.sqrt(Math.pow(x,4),3); thats what i meant... How do you resolve that
0
I am not sure but I would recon that would oerhaos make it a cube root instead of a square root.
look into Math.sqrt() on google
or run it in sololearn ide
0
well, that was what I thought too, until I saw this code, then I thought, perhaps this is something exceptional.
but when I ran the code it didn’t matter.
after some searching I can only conclude that it ignores the second parameter
x = Math.sqrt(16,3,5,102846728)
document.write(x)
#output is still 4