diff --git a/javascript/index.js b/javascript/index.js
index 9f30552db..49ddd9fc7 100644
--- a/javascript/index.js
+++ b/javascript/index.js
@@ -4,37 +4,151 @@
// 🚨🚨🚨 Comment out the below code before you start working on the code
// Out of sync
- getInstruction("mashedPotatoes", 0, (step1) => {
- document.querySelector("#mashedPotatoes").innerHTML += `
${step1}`;
- }, (error) => console.log(error));
-
- getInstruction("mashedPotatoes", 1, (step2) => {
- document.querySelector("#mashedPotatoes").innerHTML += `${step2}`;
- }, (error) => console.log(error));
-
- getInstruction("mashedPotatoes", 2, (step3) => {
- document.querySelector("#mashedPotatoes").innerHTML += `${step3}`;
- }, (error) => console.log(error));
-
- getInstruction("mashedPotatoes", 3, (step4) => {
- document.querySelector("#mashedPotatoes").innerHTML += `${step4}`;
- }, (error) => console.log(error));
-
- getInstruction("mashedPotatoes", 4, (step5) => {
- document.querySelector("#mashedPotatoes").innerHTML += `${step5}`;
- document.querySelector("#mashedPotatoesImg").removeAttribute("hidden");
- }, (error) => console.log(error));
+// getInstruction("mashedPotatoes", 0, (step1) => {
+// document.querySelector("#mashedPotatoes").innerHTML += `${step1}`;
+// }, (error) => console.log(error));
+// getInstruction("mashedPotatoes", 1, (step2) => {
+// document.querySelector("#mashedPotatoes").innerHTML += `${step2}`;
+// }, (error) => console.log(error));
+// getInstruction("mashedPotatoes", 2, (step3) => {
+// document.querySelector("#mashedPotatoes").innerHTML += `${step3}`;
+// }, (error) => console.log(error));
+
+// getInstruction("mashedPotatoes", 3, (step4) => {
+// document.querySelector("#mashedPotatoes").innerHTML += `${step4}`;
+// }, (error) => console.log(error));
+
+// getInstruction("mashedPotatoes", 4, (step5) => {
+// document.querySelector("#mashedPotatoes").innerHTML += `${step5}`;
+// document.querySelector("#mashedPotatoesImg").removeAttribute("hidden");
+// }, (error) => console.log(error));
// Iteration 1 - using callbacks
-// ...
+getInstruction(
+ 'mashedPotatoes',
+ 0,
+ (step1) => {
+ document.querySelector('#mashedPotatoes').innerHTML += `${step1}`
+ getInstruction(
+ 'mashedPotatoes',
+ 1,
+ (step2) => {
+ document.querySelector(
+ '#mashedPotatoes'
+ ).innerHTML += `${step2}`
+ getInstruction(
+ 'mashedPotatoes',
+ 2,
+ (step3) => {
+ document.querySelector(
+ '#mashedPotatoes'
+ ).innerHTML += `${step3}`
+ getInstruction(
+ 'mashedPotatoes',
+ 3,
+ (step4) => {
+ document.querySelector(
+ '#mashedPotatoes'
+ ).innerHTML += `${step4}`
+ getInstruction(
+ 'mashedPotatoes',
+ 4,
+ (step5) => {
+ document.querySelector(
+ '#mashedPotatoes'
+ ).innerHTML += `${step5}
+ Mashed potatoes are ready!`
+ document
+ .querySelector('#mashedPotatoesImg')
+ .removeAttribute('hidden')
+ },
+ (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((step0) => {
+ document.querySelector('#steak').innerHTML += `${step0}`
+ obtainInstruction('steak', 1).then((step1) => {
+ document.querySelector('#steak').innerHTML += `${step1}`
+ obtainInstruction('steak', 2).then((step2) => {
+ document.querySelector('#steak').innerHTML += `${step2}`
+ obtainInstruction('steak', 3).then((step3) => {
+ document.querySelector('#steak').innerHTML += `${step3}`
+ obtainInstruction('steak', 4).then((step4) => {
+ document.querySelector('#steak').innerHTML += `${step4}`
+ obtainInstruction('steak', 5).then((step5) => {
+ document.querySelector('#steak').innerHTML += `${step5}`
+ obtainInstruction('steak', 6).then((step6) => {
+ document.querySelector('#steak').innerHTML += `${step6}`
+ obtainInstruction('steak', 7).then((step7) => {
+ document.querySelector('#steak').innerHTML += `${step7}
+ Stake is ready!`
+ document.querySelector('#steakImg').removeAttribute('hidden')
+ })
+ })
+ })
+ })
+ })
+ })
+ })
+})
// Iteration 3 using async/await
-// ...
-
+async function makeBroccoli() {
+ const step0 = await obtainInstruction('broccoli', 0)
+ document.querySelector('#broccoli').innerHTML += `${step0}`
+ const step1 = await obtainInstruction('broccoli', 1)
+ document.querySelector('#broccoli').innerHTML += `${step1}`
+ const step2 = await obtainInstruction('broccoli', 2)
+ document.querySelector('#broccoli').innerHTML += `${step2}`
+ const step3 = await obtainInstruction('broccoli', 3)
+ document.querySelector('#broccoli').innerHTML += `${step3}`
+ const step4 = await obtainInstruction('broccoli', 4)
+ document.querySelector('#broccoli').innerHTML += `${step4}`
+ const step5 = await obtainInstruction('broccoli', 5)
+ document.querySelector('#broccoli').innerHTML += `${step5}`
+ const step6 = await obtainInstruction('broccoli', 6)
+ document.querySelector('#broccoli').innerHTML += `${step6}`
+ document.querySelector('#broccoli').innerHTML += `Broccoli is ready!`
+ document.querySelector('#broccoliImg').removeAttribute('hidden')
+}
+makeBroccoli()
// Bonus 2 - Promise all
-// ...
\ No newline at end of file
+const step0 = obtainInstruction('brusselsSprouts', 0)
+const step1 = obtainInstruction('brusselsSprouts', 1)
+const step2 = obtainInstruction('brusselsSprouts', 2)
+const step3 = obtainInstruction('brusselsSprouts', 3)
+const step4 = obtainInstruction('brusselsSprouts', 4)
+const step5 = obtainInstruction('brusselsSprouts', 5)
+const step6 = obtainInstruction('brusselsSprouts', 6)
+const step7 = obtainInstruction('brusselsSprouts', 7)
+Promise.all([step0, step1, step2, step3, step4, step5, step6, step7])
+ .then((values) =>
+ values.map(
+ (v) =>
+ (document.querySelector(
+ '#brusselsSprouts'
+ ).innerHTML += `${v}`)
+ )
+ )
+ .finally(
+ () =>
+ (document.querySelector(
+ '#brusselsSprouts'
+ ).innerHTML += `Brussels sprouts are ready!`),
+ document.querySelector('#brusselsSproutsImg').removeAttribute('hidden')
+ )