diff --git a/javascript/index.js b/javascript/index.js
index 9f30552db..a9d6994fd 100644
--- a/javascript/index.js
+++ b/javascript/index.js
@@ -6,35 +6,93 @@
// Out of sync
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}`;
+ document.querySelector("#mashedPotatoesImg").removeAttribute("hidden");
}, (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",4,(step1))
-// Iteration 2 - using promises
-// ...
+// Iteration 2 - using promises
+obtainInstruction("steak", 0)
+ .then(step0 => {
+ document.querySelector("#steak").innerHTML += `${step0}`;
+ return obtainInstruction("steak", 1);
+ })
+ .then(step1 => {
+ document.querySelector("#steak").innerHTML += `${step1}`;
+ return obtainInstruction("steak", 2);
+ })
+ .then(step2 => {
+ document.querySelector("#steak").innerHTML += `${step2}`;
+ return obtainInstruction("steak", 3);
+ })
+ .then(step3 => {
+ document.querySelector("#steak").innerHTML += `${step3}`;
+ return obtainInstruction("steak", 4);
+ })
+ .then(step4 => {
+ document.querySelector("#steak").innerHTML += `${step4}`;
+ return obtainInstruction("steak", 5);
+ })
+ .then(step5 => {
+ document.querySelector("#steak").innerHTML += `${step5}`;
+ return obtainInstruction("steak", 6);
+ })
+ .then(step6 => {
+ document.querySelector("#steak").innerHTML += `${step6}`;
+ document.querySelector("#steak").innerHTML += `Enjoy!`;
+ document.querySelector("#steakImg").removeAttribute("hidden");
+ })
+ .catch(err => {
+ console.error(err);
+ })
+ .finally(() => {
+ console.log("Good job");
+ });
// Iteration 3 using async/await
-// ...
-
+async function makeBroccoli() {
+ const ul = document.querySelector("#broccoli");
+ try {
+ for(let i=0; i < broccoli.length ;i++)
+ {
+ const step = await obtainInstruction("broccoli",i);
+ ul.insertAdjacentHTML("beforeend", `${step}`);
+ }
+ document.querySelector('#broccoliImg').removeAttribute('hidden')
+ } catch (error) {
+ console.log(error);
+
+ }
+ }
+ makeBroccoli();
// Bonus 2 - Promise all
-// ...
\ No newline at end of file
+async function renderBrusselsSprouts() {
+ const ul = document.querySelector("#brusselsSprouts");
+ try {
+ for(let i=0; i < brusselsSprouts.length ;i++)
+ {
+ const step = await obtainInstruction("brusselsSprouts",i);
+ ul.insertAdjacentHTML("beforeend", `${step}`);
+ }
+ document.querySelector('#brusselsSproutsImg').removeAttribute('hidden')
+ } catch (error) {
+ console.log(error);
+
+ }
+ }
+ renderBrusselsSprouts() ;
\ No newline at end of file