+ 4

A c JS Challenge question which Ä° don't understand

what is the output function func(x) { return function(y) { return function(z) { return x*y+z } } } document. writein(3,2,3) the correct answer is 9

19th Aug 2017, 3:08 PM
Ammar Burhani
Ammar Burhani - avatar
7 Answers
+ 15
@Ammar - post the quizz as it is, not your interpretation of it. @Kirk - the actual quizz is just fine and the correct answer is 9 😉
19th Aug 2017, 4:07 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 12
sorry, I was on the phone before :D original quizz is : function func(x) { return function(y) { return function(z) { return x*y+z; } } } document.write( func(3)(2)(3) ); so func() takes a param "x" that returns another function that takes a param "y" and returns another function that takes a param "z" and returns x*y + z; when you call func(3)(2)(3) by the time you reach the last function that returns a value x is 3, y is 2, z is 3, so the total result is 3*2+3 = 9
19th Aug 2017, 5:12 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 9
Nice explanation sir
20th Aug 2017, 12:27 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
i think you're missing semicolons sir as well as braces? if im right? correct me if im wrong sir @kirk schafer
19th Aug 2017, 4:16 PM
¤ rookie ¤
¤ rookie ¤ - avatar
+ 5
edit: it looks like the quiz is okay, see @Nikolay's answer] old....... 1: function func(x) 2: return function(y) 3: return function(z) 4: return x*y+z Uncaught SyntaxError: Unexpected token 'return', line 2. [edit: as written...] I'd report that.
19th Aug 2017, 3:23 PM
Kirk Schafer
Kirk Schafer - avatar
+ 4
@rookie - I just copied the question's text; I haven't seen the quiz itself. @Nikolay's apparently seen it so I edited my answer.
19th Aug 2017, 4:21 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Thanks! And sorry if my writing of the question wasn't clear* the question has since been corrected.
19th Aug 2017, 4:04 PM
Ammar Burhani
Ammar Burhani - avatar