Assignment with a Returned Value...?

Assignment with a Returned Value...?
0

#1

Tell us what’s happening:
Hello,
I am totally confused. I don’t get this topic AT ALL!
I copied the “hint” answer, but don’t understand what this is all about.
I’ve been matriculating so far…but this one…oy vey!
Can someone explain this to me in hard core laymen nubie code language, please?
Thanks,
Cheyena

Your code so far

// 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);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0.

Link to the challenge:


#2

I’ve seen a fcc video which explained about function and i think it could help to understand about javascript function.


#3

So the code you put at the bottom:

processed = processArg(7);

allowed you to pass the challenge. So you are not understanding why it should be written this way? Why did you write the code like this if you did not think it was going to hopefully work? Did you find the answer somewhere else and just copied/pasted this answer in? If it is the latter and you do not understand how the code produces the correct answer, then look below as I explain line by line (using comments on the right) what the code is doing:

I am going to leave out the example part, because that does not effect the outcome of passing the test, so all we have is the following:

// Setup
var processed = 0; /* the variable processed is assigned ( the equal sign) the 
                      value 0 (a number) */

function processArg(num) {  /*  a function named processArg is declared with a parameter 
                               called num */

  return (num + 3) / 5; /* since num is 7 (the argument value passed to it), it is added 
                           to 5 and then that sum is divided by 5 and the result (2) is 
                           returned back to where the function call originated (in this 
                           case processArg(7).  Because num is 7, the return statement
                           is evaluated as (7 + 3) / 5 and (10) / 5 is 2 */
}

// Only change code below this line
processed = processArg(7);  /* lastly we assign the value returned back from the function
                               to the variable named processed.  That is why processed
                               now has the value 2.  */

Hopefully, this helps you understand what the code is doing in this challenge.