Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated hints.md for fruit picker exercise #1973

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions exercises/concept/fruit-picker/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,28 @@

- Callback functions are functions passed as an argument to a calling function.
- Callback functions must meet the specification of the calling function.
- These callbacks are all synchronous, meaning they all must return a value.

## 1. Check if the grocer's service is online
## 1. Notify with a successful message

- Use the imported API function `checkStatus` in your function.
- Pass a callback function to `checkStatus`. It should expect to receive a string argument.
- Return the result from the `checkStatus` API function.
- Use the imported API function `notify` in your function.
- Pass an object to `notify`. It should have a property of `message`. Think about what the message value should be.
- Pay attention to the JSDoc type hint -- the function should not return a value.

## 2. See if the grocer has some fruit
## 2. Notify with an error message

- Use the imported API function `checkInventory` in your function.
- Create the query _object_ to pass as an argument.
- Follow the template in the instructions.
- Pass along the callback function to the `checkInventory` API function.
- Return the result from the `checkInventory` API function.
- Use the imported API function `notify` in your function.
- Pass another object to `notify`. It should have a property of `message`. The message value should differ from the last part.
- Pay attention to the comments [JSDoc] above the function definition:
- The function should not return a value.

## 3. Create a callback to buy fruit if the inventory is available
## 3. Place an order to buy fruit

- If the `err` argument is not null, throw a new error using `err`'s message.
- See [Error()][mdn-error-constructor]
- if the `err` is null, ignore it and just respond to the value of `isAvailable`
- This pattern is sometimes called a [`Node.js`-style callback][node-js-callback].
- Return the action determined by `isAvailable`
- Use the already imported `order` function.
- Pay attention to the JSDoc type hints -- the function should receive 3 arguments and not return a value.
- Reuse the previously created callbacks as arguments to the order function.

## 4. Put it all together
## 4. Refactor your work into a more concise function

- Reuse the functions you have already written, composing them together.
- Return the value of the callback function.

[mdn-error-constructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error
[node-js-callback]: https://nodejs.org/en/knowledge/getting-started/control-flow/what-are-callbacks/
- Reuse the functions from the previous tasks.
- Pay attention to the JSDoc type hints -- the function should receive 2 arguments and not return a value.
- Combine the arguments into an object representing the query to the grocer to place an order.