Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions addFood.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ function addFood(step, id, callback){
console.log(step);
document.querySelector(id).innerHTML += (`<li>${step}</li`)
resolve(step)
callback ? callback() : '' //For iteration one
callback ? callback() : ''//For iteration one //addImage(id) => function to display food image once instructions finished printing
}, Math.floor(Math.random() * 1000));
})
}
/*****^ DO NOT TOUCH *****/



// function addImage(id){
// if (id==='#mashPotatoes'){
// document.querySelector('#table').innerHTML+=`<img src="/images/mashPotatoes.jpg"/>`
// } else if (id==='#brusselSprouts'){
// return document.querySelector('#table').innerHTML+=`<img src="/images/brusselSprouts.jpg"/>`
// } else {
// return ''
// }
// }
118 changes: 109 additions & 9 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@




//Array of steps to prepare each food item
const steak = [
'season steak generously with salt, pepper and garlic powder',
'place in ziplock bag',
Expand Down Expand Up @@ -33,13 +30,116 @@ const mashPotatoes = [
'enjoy'
]


function makeFood(steps, id){
console.log('start here', steps, id)
}

//Iteration 1: Make steak instructions through use of callback functionality
// 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')
// document.querySelector('#table').innerHTML+=`<img src="/images/steak.jpg"/>`
// })
// })
// })
// })
// })
// })
// })
// Version2: using makeFood method
// function makeFood(steps, id, nextStep){
// document.querySelector(id).innerHTML+=`<li>${steps}</li>`
// if (nextStep){
// nextStep();
// }else if(!nextStep){
// document.querySelector('#table').innerHTML+=`<img src="/images/steak.jpg"/>`
// }
// }

// makeFood(steak[0], '#steak',function(){
// makeFood(steak[1], '#steak',function(){
// makeFood(steak[2], '#steak', function(){
// makeFood(steak[3], '#steak', function(){
// makeFood(steak[4], '#steak', function(){
// makeFood(steak[5], '#steak', function(){
// makeFood(steak[6], '#steak', function(){
// makeFood(steak[7], '#steak')
// })
// })
// })
// })
// })
// })
// })
//Version3: condense version 2 makeFood method call into for loop
// function makeFood(steps, id){
// document.querySelector(id).innerHTML+=`<li>${steps}</li>`
// }

// for (i=0;i<steak.length;i++){
// makeFood(steak[i], '#steak')
// if (i === steak.length-1){
// document.querySelector('#table').innerHTML+=`<img src="/images/steak.jpg"/>`
// }
// }

//Iteration 2: Make potatoes using promises (method addFood on addFood.js)
// 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')
// document.querySelector('#table').innerHTML+=`<img src="/images/mashPotatoes.jpg"/>`
// })
// })
// })
// })

//Iteration 3: Make Brusselsprouts using async and await method

// brusselSprouts.forEach(eachStep=>{
// async function mealprep(step){
// await addFood(step,'#brusselSprouts')
// if (brusselSprouts.indexOf(step) === brusselSprouts.length-1){
// document.querySelector('#table').innerHTML+=`<img src="/images/brusselSprouts.jpg"/>`
// }
// }
// mealprep(eachStep)
// })

//Version2: await for each step in brusselSprouts array
// async function prepareMeal(){
// 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')
// }

makeFood(steak, '#steak')
//Function to prepare meal in its entirety
const promises=[]
function prepareMeal(){
let foods=[steak,mashPotatoes,brusselSprouts]
let foodName=['steak','mashPotatoes','brusselSprouts']
for (let i=0;i<foods.length;i++){
let food = foodName[i]
foods[i].forEach(async function(step){
await addFood(step,`#${food}`)
if (foods[i].indexOf(step)===foods[i].length-1){
document.querySelector('#table').innerHTML+=`<img src="/images/${food}.jpg"/>`
}
promises.push(addFood(step))
})
}
}

prepareMeal()

// Promise.all(promises).then(response=>alert("Dinner is served!"))

2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ button:hover{
to {
transform: rotateX(0deg) translate(-50%, -50%) scale(1);
}
}
}