From dfd998e3222a9f52b2b8baf812950d5b56c2b579 Mon Sep 17 00:00:00 2001 From: DearTech-co Date: Sat, 6 Sep 2025 12:52:20 +0100 Subject: [PATCH] finished --- javascript/index.js | 131 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 113 insertions(+), 18 deletions(-) diff --git a/javascript/index.js b/javascript/index.js index 9f30552db..a1a6edcc9 100644 --- a/javascript/index.js +++ b/javascript/index.js @@ -3,27 +3,122 @@ // 🚨🚨🚨 Comment out the below code before you start working on the code -// Out of sync - getInstruction("mashedPotatoes", 0, (step1) => { + +getInstruction('mashedPotatoes', 0, (step0) => { + document.querySelector("#mashedPotatoes").innerHTML += `
  • ${step0}
  • `; + + getInstruction('mashedPotatoes', 1, (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', 2, (step2) => { + document.querySelector("#mashedPotatoes").innerHTML += `
  • ${step2}
  • `; + + getInstruction('mashedPotatoes', 3, (step3) => { + document.querySelector("#mashedPotatoes").innerHTML += `
  • ${step3}
  • `; + + getInstruction('mashedPotatoes', 4, (step4) => { + document.querySelector("#mashedPotatoes").innerHTML += `
  • ${step4}
  • `; + // Final message after the last step: + document.querySelector("#mashedPotatoes").innerHTML += `
  • Mashed potatoes are ready!
  • `; + + + const img = document.querySelector("#mashedPotatoesImg"); + if (img) img.removeAttribute("hidden"); + }, (err) => console.error(err)); + }, (err) => console.error(err)); + }, (err) => console.error(err)); + }, (err) => console.error(err)); + +}, (err) => console.error(err)); + - getInstruction("mashedPotatoes", 3, (step4) => { - document.querySelector("#mashedPotatoes").innerHTML += `
  • ${step4}
  • `; - }, (error) => console.log(error)); +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}
  • `; + return obtainInstruction('steak', 7); + }) + .then((step7) => { + document.querySelector("#steak").innerHTML += `
  • ${step7}
  • `; - getInstruction("mashedPotatoes", 4, (step5) => { - document.querySelector("#mashedPotatoes").innerHTML += `
  • ${step5}
  • `; - document.querySelector("#mashedPotatoesImg").removeAttribute("hidden"); - }, (error) => console.log(error)); + document.querySelector("#steak").innerHTML += `
  • Steak is ready!
  • `; + + const img = document.querySelector("#steakImg"); + if (img) img.removeAttribute("hidden"); + }) + .catch((err) => { + console.error("Error cooking steak:", err); + }); + + +// Iteration 3 - using async/await +async function makeBroccoli() { + try { + // Step 0 + const step0 = await obtainInstruction('broccoli', 0); + document.querySelector("#broccoli").innerHTML += `
  • ${step0}
  • `; + + // Step 1 + const step1 = await obtainInstruction('broccoli', 1); + document.querySelector("#broccoli").innerHTML += `
  • ${step1}
  • `; + + // Step 2 + const step2 = await obtainInstruction('broccoli', 2); + document.querySelector("#broccoli").innerHTML += `
  • ${step2}
  • `; + + // Step 3 + const step3 = await obtainInstruction('broccoli', 3); + document.querySelector("#broccoli").innerHTML += `
  • ${step3}
  • `; + + // Step 4 + const step4 = await obtainInstruction('broccoli', 4); + document.querySelector("#broccoli").innerHTML += `
  • ${step4}
  • `; + + // Step 5 + const step5 = await obtainInstruction('broccoli', 5); + document.querySelector("#broccoli").innerHTML += `
  • ${step5}
  • `; + + // Step 6 + const step6 = await obtainInstruction('broccoli', 6); + document.querySelector("#broccoli").innerHTML += `
  • ${step6}
  • `; + + // Final message + document.querySelector("#broccoli").innerHTML += `
  • Broccoli is ready!
  • `; + + const img = document.querySelector("#broccoliImg"); + if (img) img.removeAttribute("hidden"); + + } catch (err) { + console.error("Error cooking broccoli:", err); + } +} + +makeBroccoli(); + +