Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Simple JS code.

mrchow19910319
 Share

Go to solution Solved by Vinod Bahadur Thapa,

first 

console.log(bar(6)) will call the function bar(6)  //  [6 as a parameter]

then

function bar(x) { var y = 3; return foo(x*y);  // now here x=6;  than foo(3*6) = foo(18)  , now this will call foo() function 

now 

 

function foo(b) { var a = 5; return a*b+10 } // here b=18 so 5*18 + 10 ... and rule says * priority > plus sign so 90+10 = 100

which will return 100 and this is the final output :) 

please tell me this gif is wrong... right? that return 28 part is coming from where I have no idea. 

 

1_E3zTWtEOiDWw7d0n7Vp-mA.gif.6ec3a6b549a70b0ddcbc0dafc5175419.gif

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

You got the BODMAS wrong, 5*18 + 10 = (5*18) + 10 = 100

AMD R7 2700 | 2x8 3000Mhz Corsair LPX | B450M Mortar  | GTX 1070 6GB | Noctua DH-N14 | Corsair MP50 480GB | BitFenix Phenom M | Corsair AX760 | Khadas Soundboard + JDS Labs Atom | Debian 10 SID

 

Thanks let me know if I said something useful. Cheers!

Link to comment
Share on other sites

Link to post
Share on other sites

I don´t know, the image flickers and changes all the time until it stops.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, kidanime3d said:

You got the BODMAS wrong, 5*18 + 10 = (5*18) + 10 = 100

I didnt create the gif, found it online. 

so at the end of the gif it should return 100 right? 

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, mrchow19910319 said:

I didnt create the gif, found it online. 

so at the end of the gif it should return 100 right? 

Yes, 100.

 

The creator got the end of the gif wrong

AMD R7 2700 | 2x8 3000Mhz Corsair LPX | B450M Mortar  | GTX 1070 6GB | Noctua DH-N14 | Corsair MP50 480GB | BitFenix Phenom M | Corsair AX760 | Khadas Soundboard + JDS Labs Atom | Debian 10 SID

 

Thanks let me know if I said something useful. Cheers!

Link to comment
Share on other sites

Link to post
Share on other sites

If you're using Chrome or Firefox, you can test it yourself. Press F12 and click on "Console" in the developer window. Then paste that program inline:
 

function foo(b) { var a = 5; return a*b+10 } function bar(x) { var y = 3; return foo(x*y); } console.log(bar(6))

and hit enter. Should print out 100 as written.

Link to comment
Share on other sites

Link to post
Share on other sites

first 

console.log(bar(6)) will call the function bar(6)  //  [6 as a parameter]

then

function bar(x) { var y = 3; return foo(x*y);  // now here x=6;  than foo(3*6) = foo(18)  , now this will call foo() function 

now 

 

function foo(b) { var a = 5; return a*b+10 } // here b=18 so 5*18 + 10 ... and rule says * priority > plus sign so 90+10 = 100

which will return 100 and this is the final output :) 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×