diff --git a/lesson.js b/lesson.js index 55a8198..78d6c59 100644 --- a/lesson.js +++ b/lesson.js @@ -10,7 +10,7 @@ function printString(str){ printString("C"); } -//printAll(); +printAll(); // You will notice that A, B, and C print in a different and random order each time you call printAll! diff --git a/script.js b/script.js index b0246e3..12b64de 100644 --- a/script.js +++ b/script.js @@ -42,16 +42,47 @@ const mashPotatoes = [ //Iteration 1 using callbacks -- Try to streamline with recursion addFood(steak[0], '#steak', function(){ addFood(steak[1], '#steak', function(){ + addFood(steak[2], '#steak', function(){ + addFood(steak[3], '#steak', function(){ + addFood(steak[4], '#steak', function(){ + addFood(steak[5], '#steak', function(){ + addFood(steak[6], '#steak', function(){ + addFood(steak[7], '#steak', function(){ + }) + }) + }) + }) + }) + }) }) }) -//Iteration 2 using then -- Try to streamline with recursion +// Iteration 2 using then -- Try to streamline with recursion addFood(mashPotatoes[0], '#mashPotatoes').then(res => { addFood(mashPotatoes[1], '#mashPotatoes').then(res => { - - }) + addFood(mashPotatoes[2], '#mashPotatoes').then(res => { + addFood(mashPotatoes[3], '#mashPotatoes').then(res => { + addFood(mashPotatoes[4], '#mashPotatoes').then(res => { + }) + }) + }) + }) }) +//Iteration 3 + +async function printAllWithAsync(){ + await addFood(brusselSprouts[0], '#brusselSprouts'); + await addFood(brusselSprouts[1], '#brusselSprouts'); + await addFood(brusselSprouts[2], '#brusselSprouts'); + await addFood(brusselSprouts[3], '#brusselSprouts'); + await addFood(brusselSprouts[4], '#brusselSprouts'); + await addFood(brusselSprouts[5], '#brusselSprouts'); + await addFood(brusselSprouts[6], '#brusselSprouts'); + await addFood(brusselSprouts[7], '#brusselSprouts'); + await addFood(brusselSprouts[8], '#brusselSprouts'); +} +printAllWithAsync();