Why does the JS code not work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why does the JS code not work?

Inserted JS code doesn't work but it there is in JS Challenge. Do I not understand something? : ) https://code.sololearn.com/WUKxGJJDTnOs/?ref=app

16th Nov 2017, 11:18 AM
Twice Born Phoenix
Twice Born Phoenix - avatar
3 Answers
+ 7
Default parameter value doesn't work in old browsers. You may try this... function x (a, b, c) { a=a||1; b=b||5; c=c||6; return a+b-c; } document.write(x(7,4)); //output 5
16th Nov 2017, 11:32 AM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
+ 21
Function x have default parameters. When you call it x(7,4) means a=7 b=4 c=6 and 7+4-6=5 For more information: https://developer.mozilla.org/th/docs/Web/JavaScript/Reference/Functions/Default_parameters
16th Nov 2017, 11:27 AM
Nithiwat
Nithiwat - avatar
0
works fine 7+4-6=5, a=7, b=4, and c uses default of 6.
16th Nov 2017, 11:31 AM
John Wells
John Wells - avatar