 # Return Statement Wont Print

var c = a + b;
return c;
};

why doesn’t this code print out the value of 9 ?

You’re ignoring the return so nothing happens with it. The return is what value replaces the function when it’s called. To capture it, you would usually assign it to a variable and then do something with the variable.

``````var addNumbers = function(a,b) {
var c = a + b;
return c;
};
``````

Great analysis of my problem - I get it now. Just wondering how I would alter / add to the code so that whatever variables are entered for a , b, the text would out put - a + b = c

``````var addNumbers = function(a,b) {
var c = a + b;
text("added numbers:" + c, 100, 100);
return c;
};
`````` Sorry if my intent wasn’t clear - I simply wanted a printout of the equation for all values that we happened to enter for (a,b) so that the printout would look like

2 + 7 = 9

1 + 19 = 20

13 + 9 = 22 etc.,

So I am uncertain as to how to interpret the code you have written since to me it appears that the top text line of code for a = 4 and b = 5

text(“added numbers:” + c, 100, 100);

and the bottom text line of code

whereas I am simply looking for a readout - 4 + 5 = 9

So I’m not sure why we need 2 lines of code for text when both are assigned to the same location but in any case, neither line of code for text seems to give me the simple equation that I am looking for.

I did misunderstand what you were saying. Your follow-up explanation helped. What does your text function do? Does it show both your current as well as previous entries when you call it?

You would need to include the numbers yourself in your text call.

``````var added = addNumbers(4,5);
text("4 + 5 = " + added,100,100);
``````

You can wrap this up in a single function, though you start losing control over things like where to place the text.

``````var addAndDisplayNumbers = function(a,b) {
var c = a + b;
text(a + " + " + b + " = " + c,100,100);
return c;
};
``````

but you can also throw the positioning in as parameters too.

``````var addAndDisplayNumbers = function(a,b,x,y) {
var c = a + b;
text(a + " + " + b + " = " + c,x,y);
return c;
}; 