Project 26: Cryptocurrency Ticker
JS Wizard
Builds on these lessons
Step 1 of 3
Project
Debouncing Price Updates
Write debounce(fn, delay) — it clears any pending timer and starts a new one on every call, so fn only actually runs once activity has paused for delay ms. Wrap a searchCoin function in it so a fast typist searching for "bitcoin" only triggers one real lookup, not one per keystroke.
🎯 Your Task
Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!
function debounce(fn, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), delay);
};
}
function searchCoin(query) {
console.log("Searching for:", query);
}
const debouncedSearch = debounce(searchCoin, 300);
debouncedSearch("bit");
debouncedSearch("bitc");
debouncedSearch("bitcoin");