Problems with Challenge Assignment with a Returned Value?

Im having trouble understanding whats wrong with my code, anyone have solutions to this challenge and is able to explain what i have done wrong?

The instructions say

Call the processArg function with an argument of 7 and assign its return value to the variable processed.

An example of a function call can be seen at line 9. You just have to do something like that below the last comment.

What you did is that you declared a function with the name processArg (which replaces the earlier processArg function).

1 Like

Still confused…could you give me a hint how to do this please?

2 Likes

You’re close!

Look at the first half of the code (up until before Setup).

The variable changed is assigned the value that you get from the call to the function change.

You want to do the same, but with the variable processed and the function processArg.

5 Likes

finally solved it! Thx for help man!

1 Like

This was a difficult problem and I figured out the solution to it. The solution is:

// 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
var processed = 2;

function processArg(num) {

return (num * 1 ) / 3.5;
}
processed = processArg(7);

3 Likes

I have done it like this:

var processeArg = 2;

function processed(num) {
  return (num + 2 ) + 8;
}

processed = processArg(7);
4 Likes

Why we dont do it 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);

5 Likes

Should I, at this point in the lessons, understand why variable “processed” is initially assigned a value of 0 or should I not worry about that right now?:

var processed = 0;

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

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

I wrote this to help out any questions that might come up in the future and to help me clarify my own understanding.
IF anything is incorrect please help correct it.

var changed = 0;

The variable object ‘changed’ is created and initialized to a numeric value of zero OUTSIDE function. (global scope)
You need to assign a numeric variable value to object ‘changed’ before you can use it in the code below.
The Computer reads code from top-to-bottom. (more or less as it executes the code)
The ‘changed’ objects’ variable assignment location at the machine-level code can then take a numeric value.
IF you assigned it a " string literal " using quotes, it would want a string value instead.

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

A function created and a single parameter named num to take a single argument on a function call.
The statement here: On the right of ‘return’ is evaluated first: and the result is returned to the called function.
e.g., change(10). Nothing happens inside the body of the function until the function is called.

changed = change(10);

The function call on right ‘change(10)’ is executed and the value ‘10’ passed in as an argument to the parameter num. (10 + 5) / 3 = 5.
The numeric value ‘5’ is returned to the rvalue(on the right of the assignment operator ‘=’ ) Code now see’s; changed = 5;
The numeric value ‘5’ is assigned to the variable ‘changed’.

// Setup

var processed = 0;

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

// Only change code below this line

processed = processArg(7);

5 Likes

Thanks for breaking that down. Struggled a little with this exercise. Your explanation set me straight.

Hi.
Late comer .
At the moment i am doing this . I have done it before coming to this page. but I am still getting :You should assign processArg to processed. . i will do a cookie cache . maybe that is me

Hi now it is sorted. Did the cache clear and, Maybe I was just missing my semi;colon. …walks sheepishly away

Thank you you helped me a lot because i couldn’t find an answer