Skip to content

Commit

Permalink
npx prettier -w
Browse files Browse the repository at this point in the history
  • Loading branch information
neenjaw committed May 2, 2022
1 parent 3d7b81a commit fe60906
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion concepts/callbacks/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ It is also useful to use _callback functions_ because they may reference variabl
_Event handlers_ are a common use-case for callbacks in JavaScript. Browser events like `'onload'` or `'onclick'` are signals which can trigger functions to be invoked. A DOM [[Document Object Model](mdn-dom) object's `addEventListener` method registers a callback function to be invoked when it "hears" that an event has occurred.

```javascript
document.addEventListener('onload', () => alert('The webpage has now been loaded'))
document.addEventListener('onload', function () {
alert('The webpage has now been loaded');
});
```

### Node.js Convention
Expand Down
16 changes: 10 additions & 6 deletions exercises/concept/fruit-picker/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ You are creating a new online portal for your patrons to order their fruit fresh

## 1. Create a callback to be called when the order is successful

Write a callback function called `onSuccess` to be called when the order is successful. It should invoke the imported `notify` function passing a success message to it.
Write a callback function called `onSuccess` to be called when the order is successful. It should invoke the imported `notify` function passing a success message to it.

```javascript
onSuccess();
// => `nofify` called with `{ message: 'SUCCESS' }`
// => `notify` called with `{ message: 'SUCCESS' }`
```

## 2. Create a callback to be called when the order fails with an error

Write a callback function called `onError` to be called when the order encounters an error. It should invoke the imported `notify` function passing an error message to it.
Write a callback function called `onError` to be called when the order encounters an error. It should invoke the imported `notify` function passing an error message to it.

```javascript
onError();
// => `nofify` called with `{ message: 'ERROR' }`
// => `notify` called with `{ message: 'ERROR' }`
```

## 3. Create a wrapper to wrap the external api function
Expand All @@ -34,7 +34,11 @@ const query = {
```

```javascript
orderFromGrocer({variety: 'pear', quantity: 12}, exampleSuccessCallback, exampleErrorCallback)
orderFromGrocer(
{ variety: 'pear', quantity: 12 },
exampleSuccessCallback,
exampleErrorCallback
);
// => `order` was called with the query and the callbacks
```

Expand All @@ -43,6 +47,6 @@ orderFromGrocer({variety: 'pear', quantity: 12}, exampleSuccessCallback, example
You find that you are calling this function from many different places with the same functions. Seeing an opportunity to refactor your code, you want to create a function where you can supply the variety and quantity to order as arguments.

```javascript
postOrder('peach', 100)
postOrder('peach', 100);
// => order submitted for 100 peaches
```

0 comments on commit fe60906

Please sign in to comment.