Freecodecamp: Console capture does not log when message is falsy

Created on 28 Nov 2016  Â·  10Comments  Â·  Source: freeCodeCamp/freeCodeCamp

Challenge Passing Values to Functions with Arguments has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 OPR/41.0.2353.69.

Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


// Example
// Only change code below this line.

function functionWithArgs(c, d) {
 console.log(c + d); 
}
functionWithArgs(7,-7); // result is 'console.log never called '

Result should be 0, but is not. 



help wanted discussing

All 10 comments

Your code passes for me. Can you try checking by resetting the code, and/or deleting the cookies, and then reattempting the challenge?

@BlindAmbition you've deleted the original seed code and that is why you're getting the weird console log. If you add the following code back into your code, you won't see any issues.

function ourFunctionWithArgs(a, b) {
  console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5

Please take note of comments in the editor when you start. Some will have // Only change code below this line. which are important to notice when completing the challenge. Closing as a non-bug issue. Happy coding!

Hi ,Eric,

Thank you for the quick feedback.

However, no, it won't, I'm sorry.
I reset the problem, and put my own code in, and then the result is not
0, but 5.
Being the result from the example. Which is why I removed it while
toying with it.

You may be right that it is not a bug, but it IS kinda weird that using
7 + -7 does not give 0 as a result.
It should, and I asked around and when NOT in FCC area, it does, but it
bugs me I can't get it to work, and I don't know why.

Please find attached a screenshot of the result after resetting the
page, and adding my code while the example code stays intact.
As you can see the output is now 5, which is really not the correct one
for 7 + -7.

Help?

Cheers,

BlindAmbition aka Martin

On 11/28/2016 21:14, Eric Leung wrote:
>

@BlindAmbition https://github.com/BlindAmbition you've deleted the
original seed code and that is why you're getting the weird console
log. If you add the following code /back/ into your code, you won't
see any issues.

function ourFunctionWithArgs(a,b) {
console.log(a- b);
}
ourFunctionWithArgs(10,5);// Outputs 5

Please take note of comments in the editor when you start. Some will
have |// Only change code below this line.| which are important to
notice when completing the challenge. Closing as a non-bug issue.
Happy coding!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/11846#issuecomment-263380407,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVNmRy-JLlSBzrw7MIRbhMFUNqAC7Wu6ks5rCzYMgaJpZM4K9-yM.


This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

@BlindAmbition thanks for the response. Ah I see. Yes, I agree that this might come off as confusing.

It seems that something in the background is failing for when you have a difference/sum equal to zero for the functionWithArgs() function, like functionWithArgs(-4, 4). If you have something that is positive or negative like functionWithArgs(4, 1) or functionWithArgs(3, -4), then the console on the site will show the correct value.

cc/ @FreeCodeCamp/moderators I suspect something within these lines is causing an issue, but that is just a hunch.

Ah! Your hunch is right :smiley: @erictleung
This line https://github.com/FreeCodeCamp/FreeCodeCamp/blob/staging/seed/challenges/01-front-end-development-certification/basic-javascript.json#L2358 should read

logOutput = JSON.stringify(message).trim();",

The if statement is unnecessary.

When message == 0, it won't output anything. :no_good_man: according to https://github.com/FreeCodeCamp/FreeCodeCamp/blob/staging/seed/challenges/01-front-end-development-certification/basic-javascript.json#L2308

@abhisekp thanks for cleaning that up! I forgot that "0" == false evaluates to true 😄

...[...]... should read

logOutput = JSON.stringify(message).trim();",

The if statement is unnecessary.

Nope. The check is required to avoid throwing exceptions. Never assume a param to be passed correctly.

Ex: It's failing in the PR's case because it's undefined for some caller. Callee should validate before using any params.

Need a better workaround than this.

Ugh....

logOutput = String(JSON.stringify(message, null, 2)).trim()

:unamused:

I'll make the PR with @abhisekp fix.

What's interesting to me is that most of the following challenges (global scope challenge and the local scope challenge) don't verify the message at all, nor stringify it.
The message "console.log was never called" is never shown because of the seed, so it's a bit weird that it even exists.
I think it would be a good idea to make sure it's consistent for all challenges where it is used, if that's possible.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bagrounds picture bagrounds  Â·  3Comments

robwelan picture robwelan  Â·  3Comments

SaintPeter picture SaintPeter  Â·  3Comments

danielonodje picture danielonodje  Â·  3Comments

vaibsharma picture vaibsharma  Â·  3Comments