Freecodecamp: Issue with Return a Value from a Function with Return

Created on 6 Jul 2016  路  19Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Return a Value from a Function with Return has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:
function timesFive(num){
return num * 5;
}
var answer = timesFive(5);

// Example
function minusSeven(num) {
return num - 7;
}
var answer = minusSeven(7);
// Only change code below this line

**The console deck won't change no matter what you type in. Always showing "timesFive(5)===25".**

People who have this kind of problem could go to this link and test:
https://jsbin.com/daxoyifabe/edit?html,css,output
help wanted

Most helpful comment

This has to do with how the challenge code and tests are run when a user clicks "Run Tests." In this case, the "tail" of the challenge attempts to call timesFive with an argument of 5 if it is a valid function and returns the result to show the user what the output is for that input, and returns "timesFive is not a function" otherwise.

However in many other challenges, the output will reflect the returned value of a call to the function if one is included at the end of the code, but this is not the case here. Even with the final line timesFive(2) (with or without assignment to a variable) the output will display "timesFive(5)===25" as @zcloud421 correctly stated.

The challenge tail should be reviewed to allow users to test their own values with their newly written function, as this is one of the first opportunities in the course for them to do so (with a function written from scratch). As assigning the returned value of the function to answer prevents the output from displaying, this should probably be removed from the example code also. It isn't really needed since answer is not subsequently used, and "Assignment with a Returned Value" is the aim of the following challenge anyway.

All 19 comments

This has to do with how the challenge code and tests are run when a user clicks "Run Tests." In this case, the "tail" of the challenge attempts to call timesFive with an argument of 5 if it is a valid function and returns the result to show the user what the output is for that input, and returns "timesFive is not a function" otherwise.

However in many other challenges, the output will reflect the returned value of a call to the function if one is included at the end of the code, but this is not the case here. Even with the final line timesFive(2) (with or without assignment to a variable) the output will display "timesFive(5)===25" as @zcloud421 correctly stated.

The challenge tail should be reviewed to allow users to test their own values with their newly written function, as this is one of the first opportunities in the course for them to do so (with a function written from scratch). As assigning the returned value of the function to answer prevents the output from displaying, this should probably be removed from the example code also. It isn't really needed since answer is not subsequently used, and "Assignment with a Returned Value" is the aim of the following challenge anyway.

I agree with @BKinahan and since at this point in the curriculum, the campers don't have an idea to do a console.log(returnedValue) and see the results in the console, we should provide a way for them to see the results and understand what their code is doing as supposed to what it should do.

See #8302

I agree with @BKinahan too. So, how can we change the way the result is printed on output? What part of codebase prints the result of the student's code?

The code that does this is in this line of code. I agree. It should be modified a bit so it doesn't confuse the camper.

Would it be better rather than showing those strings, it showed the results of the function that they called?
Example: timesFive(5), would result in them seeing the value of 25 in the code mirror?

This one is up for grabs.

How do we want to go about this?

+1

Some images to help understanding the problem:

With the following code:

I would like to work on this issue.

Hi @wjhurley! How's your progress on this?

@systimotic I honestly haven't gotten anywhere with this yet. I was trying to figure out why I can't seem to get my code to print to the output window on my local copy, and when I asked about this problem in the Contributors gitter chat room, @raisedadead pointed me to this: https://github.com/FreeCodeCamp/FreeCodeCamp/issues/9363
So as far as I know, we're no longer printing to the output window, but then @raisedadead says this: "@wjhurley they sure are taught. And the output box will be used. It just has a need to change the code from the seed.
You can make smaller PRs should you feel its tedious to all at once!
Just make sure to comment on the main issue as you go along"
Honestly, I'm confused as hell now. I don't know what it is we're trying to do and if it matters or not that my output window does not work on my local version of FCC.

@wjhurley Sorry for the confusion and the late reply! Let me try to clear things up:

In the live version of the site, whatever is returned is what is outputted to the output window. In the beta version (which is the one we're working on here on GitHub), this has been changed. Return output is now ignored, but all console output is being shown in the output window.
This means that all function calls that should have a visible output, should be wrapped in a console.log() statement. That is the aim of the issue you referenced.

Here's what I think should be done to resolve this issue:

  1. Remove the tail
  2. Add some code to the seed that logs a call to the newly created function, below a "do not edit below this..." comment.

I hope that clears things up. If you need more information, feel free to pop back on Gitter (you can DM me if you wish 馃檪)

Since this has been inactive for a while, I thought I'd give this a shot :smile:

Challenge: Basic Java script - Assignment with a Returned Value

image

The code looks like this:


// Example
var changed = 0;

function change(num) {
  return (num + 5) / 3;
}

changed = change(10);

// Setup
var processed = 0;

function processArg(num) {
  return (num + 3) / 5;
}

// Only change code below this line
processed= processArg (7);

The result in the console window is this:
processed =2
The feedback is:

Correct: processed should have a value of 2
Incorrect: You should assign processArg to processed

I included a screendump. I don鈥檛 understand if I am doing something stupid, I apologise in advance if I am only wasting your time.
Please tell me if I am missing something here.
Regards and thanks

I was able to get rid of this problem, I reset my code and that removed the issue. I must admit that I created the solution just before the last poster worked on the problem, the old version must have been saved somehow. Now, I was able to continue with the next challenge.

@Kathumark Glad you solved it! I think this can have been related to the lack of a space before the equal sin on the final line of your solution.

Sometimes the tests expect a certain format of the code, even though the code is perfectly functional.

Good luck and happy coding! :smile:

Destroyed challenge

                   Returning a Value from a Function with Return.

First in this lesson we're asked to Create a function timesFive that accepts one argument, multiplies it by 5, and returns the new value.
LINES:
1 // Function creation below
2 function timesFive(num) {
return num * 5;
};
3 // Calling function timesFive with a number to return 25 as instructed
4 timesFive(5);

When the above code is been debugged the output of will be a new value of 25. Thanks.

Was this page helpful?
0 / 5 - 0 ratings