+ 2

Javascript Math question

Hello guys. var x = 2; var y = Math.sqrt(Math.pow(x,4),2); Alert(y) Can someone explain please

17th Aug 2019, 6:01 PM
David
David - avatar
13 odpowiedzi
+ 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
17th Aug 2019, 8:41 PM
Brave Tea
Brave Tea - avatar
+ 3
you are welcome. thanks for sticking with me :)
17th Aug 2019, 9:15 PM
Brave Tea
Brave Tea - avatar
+ 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)
17th Aug 2019, 6:43 PM
Brave Tea
Brave Tea - avatar
+ 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)
17th Aug 2019, 8:47 PM
David
David - avatar
+ 2
Wow, that was very tricky hahaha. Thank you a lot for your time and help! Appreciate it
17th Aug 2019, 9:08 PM
David
David - avatar
0
Also: var x = Math.pow(Math.floor(Math.sqrt(4)),2) alert(x)
17th Aug 2019, 6:04 PM
David
David - avatar
0
These 2 questions were in JS challenge, i put 2 as a result, thinking it is true, but 4 is the right answer
17th Aug 2019, 7:15 PM
David
David - avatar
0
so yeah, if the answer was 4 then my explanation pans out :)
17th Aug 2019, 7:19 PM
Brave Tea
Brave Tea - avatar
0
Alright but what if, for example number 3 would have been put instead of number 2? How would you calculate that
17th Aug 2019, 7:41 PM
David
David - avatar
0
which 2 do you want to substitute?
17th Aug 2019, 7:53 PM
Brave Tea
Brave Tea - avatar
0
Var y = Math.sqrt(Math.pow(x,4),3); thats what i meant... How do you resolve that
17th Aug 2019, 8:10 PM
David
David - avatar
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
17th Aug 2019, 8:16 PM
Brave Tea
Brave Tea - avatar
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
17th Aug 2019, 8:54 PM
Brave Tea
Brave Tea - avatar