thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

13.04 · Reusable functions / Practice · 5 min

Send a result back

The calculator computes a sum, but the caller receives undefined.

Activity 4 of 6 in Reusable functions

All courses

JavaScript Basics / 13.04

Send a result back

Not started

The calculator computes a sum, but the caller receives undefined.

More options
Rob places two number tokens into a calculator, sees an empty return tray, then checks the route from the calculation to the caller’s tray.
Rob’s comic strip · Reusable functions

Define a function, call it and use its return value

Work through 4 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

4 steps · Saved work · Instant feedback

YOUR TURN

Return the calculated total

In add, replace the calculation-only line with a return statement. Keep the two calls and print 8 and 10. Do not print from inside add.

Expected output
8
10

Keep the starting inputs. Print these lines in this order, without extra output.

Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
function add(a, b) {
  a + b;
}
console.log(add(3, 5));
console.log(add(4, 6));

Need a nudge?

Follow the values

The caller needs the result. Merely evaluating a + b inside the body does not send it back.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Return the result instead of only calculating or printing it.