Created
January 25, 2022 09:26
-
-
Save midorikocak/19ca4d2144f603721c298537afdbe190 to your computer and use it in GitHub Desktop.
Callback repeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let songs = ["Nothing else matters", "Baby, one more time", "Laura non c'è"]; | |
function haveAParty(musicPlayer, songs, neighborsComplained) { | |
if (neighborsComplained === false) { | |
songs.forEach((song) => { | |
musicPlayer(song); | |
}); | |
} | |
} | |
function turnTable(song) { | |
console.log(`I'm playing ${song} on turn table`); | |
} | |
function cdPlayer(song) { | |
console.log(`I'm playing ${song} on cd player`); | |
} | |
function walkman(song) { | |
console.log(`I'm playing ${song} on walkman`); | |
} | |
haveAParty(turnTable, songs, true); | |
haveAParty(cdPlayer, songs, false); | |
haveAParty(walkman, songs, false); | |
haveAParty( | |
function (song) { | |
console.log(`I'm playing ${song} on iPod`); | |
}, | |
songs, | |
false | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment