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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
<script src="javascript/data.js"></script>
<script src="javascript/getInstruction.js"></script>
<script src="javascript/obtainInstruction.js"></script>
<script src="javascript/index.js"></script>
<script type="module" src="javascript/index.js"></script>
</body>
</html>
5 changes: 3 additions & 2 deletions javascript/data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const steak = [

const steak = [
"season steak generously with salt, pepper and garlic powder",
"place in zip lock bag",
"cook in sous vide at 120 F for 1-2 hours",
Expand Down Expand Up @@ -36,4 +37,4 @@ const broccoli = [
'cook for 3 to 4 minutes, or until tender',
'drain, then leave to steam dry for a minute',
'enjoy'
];
];
153 changes: 128 additions & 25 deletions javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,140 @@
// 🚨🚨🚨 Comment out the below code before you start working on the code

// Out of sync
getInstruction("mashedPotatoes", 0, (step1) => {
document.querySelector("#mashedPotatoes").innerHTML += `<li>${step1}</li>`;
}, (error) => console.log(error));

getInstruction("mashedPotatoes", 1, (step2) => {
document.querySelector("#mashedPotatoes").innerHTML += `<li>${step2}</li>`;
}, (error) => console.log(error));

getInstruction("mashedPotatoes", 2, (step3) => {
document.querySelector("#mashedPotatoes").innerHTML += `<li>${step3}</li>`;
}, (error) => console.log(error));

getInstruction("mashedPotatoes", 3, (step4) => {
document.querySelector("#mashedPotatoes").innerHTML += `<li>${step4}</li>`;
}, (error) => console.log(error));

getInstruction("mashedPotatoes", 4, (step5) => {
document.querySelector("#mashedPotatoes").innerHTML += `<li>${step5}</li>`;
document.querySelector("#mashedPotatoesImg").removeAttribute("hidden");
}, (error) => console.log(error));
// getInstruction("mashedPotatoes", 0, (step1) => {
// document.querySelector("#mashedPotatoes").innerHTML += `<li>${step1}</li>`;
// }, (error) => console.log(error));

// getInstruction("mashedPotatoes", 1, (step2) => {
// document.querySelector("#mashedPotatoes").innerHTML += `<li>${step2}</li>`;
// }, (error) => console.log(error));

// getInstruction("mashedPotatoes", 2, (step3) => {
// document.querySelector("#mashedPotatoes").innerHTML += `<li>${step3}</li>`;
// }, (error) => console.log(error));

// getInstruction("mashedPotatoes", 3, (step4) => {
// document.querySelector("#mashedPotatoes").innerHTML += `<li>${step4}</li>`;
// }, (error) => console.log(error));

// getInstruction("mashedPotatoes", 4, (step5) => {
// document.querySelector("#mashedPotatoes").innerHTML += `<li>${step5}</li>`;
// document.querySelector("#mashedPotatoesImg").removeAttribute("hidden");
// }, (error) => console.log(error));

// Iteration 1 - using callbacks
// ...
getInstruction(
"mashedPotatoes",
0,
(step1) => {
document.querySelector("#mashedPotatoes").innerHTML += `<li>${step1}</li>`;
getInstruction(
"mashedPotatoes",
1,
(step2) => {
document.querySelector(
"#mashedPotatoes"
).innerHTML += `<li>${step2}</li>`;
getInstruction(
"mashedPotatoes",
2,
(step3) => {
document.querySelector(
"#mashedPotatoes"
).innerHTML += `<li>${step3}</li>`;
getInstruction(
"mashedPotatoes",
3,
(step4) => {
document.querySelector(
"#mashedPotatoes"
).innerHTML += `<li>${step4}</li>`;
getInstruction(
"mashedPotatoes",
4,
(step5) => {
document.querySelector(
"#mashedPotatoes"
).innerHTML += `<li>${step5}</li>`;
document
.querySelector("#mashedPotatoesImg")
.removeAttribute("hidden");
document.querySelector(
"#mashedPotatoes"
).innerHTML += `<li> Mashed potatoes are ready!</li>`;
},
(error) => console.log(error)
);
},
(error) => console.log(error)
);
},
(error) => console.log(error)
);
},
(error) => console.log(error)
);
},
(error) => console.log(error)
);

// Iteration 2 - using promises
// ...

obtainInstruction("steak", 0)
.then((response) => {
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
return obtainInstruction("steak", 1)
.then((response) => {
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
return obtainInstruction('steak',2)
.then((response)=>{
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
return obtainInstruction('steak',3)
.then((response)=>{
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
return obtainInstruction('steak',4)
.then((response)=>{
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
return obtainInstruction('steak',5)
.then((response)=>{
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
return obtainInstruction('steak',6)
.then((response)=>{
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
return obtainInstruction('steak',7)
.then((response)=>{
document.querySelector("#steak").innerHTML += `<li>${response}</li>`;
document.querySelector('#steak').innerHTML += `<li>Your Steak is ready!</li>`
}).catch((reject)=> console.log('error: ',reject))
})
})
})
})
})
})
})
// Iteration 3 using async/await
// ...
async function makeBroccoli(){
try {
const step1 = await obtainInstruction('broccoli',0)
document.querySelector("#broccoli").innerHTML += `<li>${step1}</li>`;
const step2 = await obtainInstruction('broccoli',1)
document.querySelector("#broccoli").innerHTML += `<li>${step2}</li>`;
const step3 = await obtainInstruction('broccoli',2)
document.querySelector("#broccoli").innerHTML += `<li>${step3}</li>`;
const step4 = await obtainInstruction('broccoli',3)
document.querySelector("#broccoli").innerHTML += `<li>${step4}</li>`;
const step5 = await obtainInstruction('broccoli',4)
document.querySelector("#broccoli").innerHTML += `<li>${step5}</li>`;
const step6 = await obtainInstruction('broccoli',5)
document.querySelector("#broccoli").innerHTML += `<li>${step6}</li>`;
const step7 = await obtainInstruction('broccoli',6)
document.querySelector("#broccoli").innerHTML += `<li>${step7}</li>`;
document.querySelector('#broccoli').innerHTML += `<li>Your Broccoli is ready!</li>`
} catch (error) {
console.log(error)
}
}
makeBroccoli()

// Bonus 2 - Promise all
// ...
// ...
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

body {
padding: 20px;
background-color: #363535;
}

img {
Expand All @@ -13,7 +14,7 @@ img {
li {
font-size: 16px;
line-height: 1.5rem;
color: #545454;
color: #fdf6f6;
/* text-transform: capitalize; */
}

Expand Down Expand Up @@ -72,7 +73,7 @@ button {
font-size: 3rem;
padding: 1rem;
background: #eeeeee;
color: black;
color: rgb(239, 227, 227);
transition: all.2s;
}

Expand Down