## Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

### Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today. # Please explain the last example with the CPS

Why is the result 65 and what does the `(n)` argument in each callback refer to? The callback or the numbers that are given as arguments?

It is melting my non-mathematical brain. ```function add(x, y, callback) {
callback(x + y)
}

function subtract(x, y, callback) {
callback(x - y);
}

function multiply(x, y, callback) {
callback(x * y);
}

function calculate(x, callback) {
callback(x);
}

calculate(5, (n) => {
add(n, 10, (n) => {
subtract(n, 2, (n) => {
multiply(n, 5, (n) => {
console.log(n); // 65
});
});
});
});
```

On line 13 we're defining a function called `calculate`. It has two parameters, `x` and `callback`; `x` will be a number and `callback` will be a function. Inside of the body of `calculate`, we're calling the function `callback` passing in the value of `x` as the first argument for that function. (I should note here that I'm using the terms parameter and argument to mean different things, as explained here):

The later on, on line 17, we call the calculate function. 5 is passed in as the first argument. And a new anonymous arrow function is passed in as the 2nd argument, which is defining the function in place. In the definition of that function, it takes a parameter `n`. In this example, at runtime, `n` will be 5, because that's what we're passing in as the 1st argument to `calculate` on line 17, and if we flip back to the function definition on line 13, that number 5 will then be `x` and then on line 14 `x` gets passed in to the callback. So 5 is `x` and `x` is `n` when things kick off here.

It's not that easy to follow. It took me a minute to untangle it. My preference is not to use this kind of 'continuation-passing style', which is also referred to less positively as "callback hell" or "pyramid of doom". Here's an alternative version without anonymous functions, defining those functions separately. It's still tricky to follow but at least it's an alternative version of the same thing that may help you connect some dots. (I also made all the functions into arrow functions for consistency)

```const add = (x, y, callback) => {
callback(x + y)
}

const subtract = (x, y, callback) => {
callback(x - y);
}

const multiply = (x, y, callback) => {
callback(x * y);
}

const calculate = (x, callback) => {
callback(x);
}

/***** calbacks *****/

const onMultiply = (n) => {
console.log(n); // 65
}

const onSubtract = (n) => {
multiply(n, 5, onMultiply);
}

const onAdd = (n) => {
subtract(n, 2, onSubtract);
}

const composedCalculator = (n) => {