大家晚上好!我的代码有一个小问题,无法正确解决。我需要通过回调函数将最简单的汤配方输出到控制台。请帮助提供建议。预先感谢!
从在线教程和 YouTube 中,我了解到如果我们将一个函数作为参数传递给另一个函数,那么这是一个回调函数。
// Put the water to boil
function setWater(param){
console.log('We start to cook the soup. We put the water to warm.');
param();
}
// Chop the onion
function cutOnion(param){
setTimeout(() => {
console.log('Chop the onion');
param();
}, 5000);
}
// Chop the carrot
function cutCarrot(param){
setTimeout(() => {
console.log('Chop the carrot');
param();
}, 6000);
}
// We are waiting for the water to boil.
function waitForWater(param){
setTimeout(() => {
console.log('We are waiting for the water to boil.');
param();
}, 10000);
}
// Put the onion in the water
function putOnion(param){
setTimeout(() => {
console.log('Put the onion in the water');
param();
}, 12000);
}
// Put the carrot in the water
function putCarrot(param){
setTimeout(() => {
console.log('Put the carrot in the water');
param();
}, 14000);
}
// Soup Is Ready
function soupIsReady(){
setTimeout(() => {
console.log('Soup is ready');
}, 20000);
}
setWater(cutOnion);
cutOnion(cutCarrot);
cutCarrot(waitForWater);
waitForWater(putOnion);
putOnion(putCarrot);
putCarrot(soupIsReady)
我需要在计时器上依次执行这些功能。
千万里不及你
眼眸繁星
holdtom
相关分类