Hey there! There is something wrong with the exercise, I guess.
I am really confused with callbacks. Instructions explain that callbacks need a “return”, however in fruit-picker exercise the imported functions don’t work in the same way.
Keeping this in mind, the “notify” and “order” imported functions are not correctly defined in their documents (notifier.js and grocer.js), because they don’t have a “return” and It should return “undefined”. But, the next solution was successful:
export function onSuccess() {
// implement the onSuccess callback to call notify with a success message
return notify({"message": "SUCCESS"});
}
Nevertheless I have checked the same with TypeCript online simulator and the output was the expected “undefined”.
Thanks to Ian-tang because he resolved my question in a mentoring session:
The exercise is pretty simplistic, so the notify and order functions are just stubs to provide a function signature. In other words, there is no expected output from these functions. The tests ensure that you are calling the functions with the correct inputs.
I don’t see anything incorrect with the documentation:
/**
* @param {FruitPickerSuccess | FruitPickerError} message
* @return void
*/
export function notify(message) {
// This is a mocked function for use with the exercise.
message;
}
void in JavaScript means it will execute whatever is next to it, and then return undefined. You shouldn’t need to know this to complete the exercise, but it returning undefined is both expected and documented.
Mocking a function means that we do not show you how it’s implemented and instead show you a fake version (a mock) so you can work with it. Sometimes a mock version replaces a real implementation and sometimes a mock version is replaced by an implementation. The purpose of mocking is usually that you want to test specific behaviour to happen when the mocked version is used, or you want to ensure a specific value is returned from it.
In this exercise the instruction say you should call (use) notify with a specific value. It says nothing about returning anything. I checked for you, but nowhere in the instructions does it say a callback must return something.
Could you let us know how we can improve the instructions here?
Sorry but english is not my mother tongue and is really difficult to explain me better.
This would be fine like an annotation in the instructions, because “mock” also could be interpreted like a real example, but in a restricted conditions.
You should think that people is learning this at the first time.
Anyway, the exercise It’s fine but a little bit confusing for me.
The tracks are not really well engineered for first-time programmers, but mostly meant for programmers coming from other languages. We do have a bootcamp for first timers.
If you are a new coder, congrats on getting this far. That’s really great!!