diff --git a/arrays.js b/arrays.js index 37faed2..4877a43 100644 --- a/arrays.js +++ b/arrays.js @@ -16,6 +16,14 @@ Expected Output: // ✍️ Solve it here ✍️ +const inventory = ["Apples", "Bread", "Milk", "Eggs"]; + +inventory.push("Oranges","Bananas"); +console.log(inventory.shift()) + + +console.log(inventory) + @@ -40,7 +48,17 @@ Output: "Ali is present." // ✍️ Write your function here ✍️ +const students = ["Ali", "Fatima", "Hassan", "Layla"]; + +function isPresent(name) { + if (students.includes(name)) { + return `${name} is present.` + } else { + return `${name} is absent.`; + } +} +console.log(isPresent("Ali")) @@ -68,11 +86,6 @@ Output: Sorted leaderboard with updated scores // ✍️ Write your functions here ✍️ - - - - - /* STRETCH TASK: **The Ultimate Treasure Hunt** 🗺️💎🏴‍☠️ diff --git a/callbacks.js b/callbacks.js index 3fadb3f..3c2cf00 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,7 +18,12 @@ Expected Output: // ✍️ Solve it here ✍️ - +function sendMessage(username,cb) { + return cb(`Welcome, ${username}`) + } +sendMessage("Amina", theCallBackFunction) +function theCallBackFunction(welcome){ +console.log(welcome)} /* @@ -48,7 +53,20 @@ Expected Output: // ✍️ Solve it here ✍️ - +function checkTemperature(tempv,cb){ + +return cb(tempv)} +function theCallbackFunction(tempv){ + if (tempv >30){ + console.log("hot") + } + else if (tempv >= 15 && tempv <= 30){ + console.log("warm")} + else { + console.log("cold") + } +} +checkTemperature(35,theCallbackFunction) /* diff --git a/index.html b/index.html index 1104b64..b3efd6a 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,10 @@

Look at the console to see the results

+ + + + \ No newline at end of file diff --git a/objects.js b/objects.js index e2426e9..41eec47 100644 --- a/objects.js +++ b/objects.js @@ -30,8 +30,22 @@ Expected Output: // ✍️ Solve it here ✍️ +const gamerProfile = { + username: "ShadowSlayer", + level: 5, + isOnline: false +}; +function updateOnlineStatus(gamerProfile, status) { + gamerProfile.isOnline = status; + if (status) { + console.log(`${gamerProfile.username} is now online.`); + } else { + console.log(`${gamerProfile.username} is now offline.`); + } +} +updateOnlineStatus(gamerProfile, true) /* Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗 @@ -64,6 +78,21 @@ Expected Output: // ✍️ Solve it here ✍️ +const dress= { + name: "EveningGown", + size: "m", + inStock: true, +} +function checkAvailability(dress) { + if (dress.inStock){ + console.log(`${dress.name} is available in size ${dress.size}.`) + } + else{ + console.log (`${dress.name} is out of stock.`) + } + } +checkAvailability (dress) + /* @@ -104,3 +133,17 @@ Features: */ // ✍️ Solve it here ✍️ +const supercar = { + model: "Ferrari SF90", + price: 500000, + features: { + color: "Red" + } +}; +function addFeature(supercar, featureName) { + supercar.features[featureName] = true; + console.log(`${featureName} has been added to ${supercar.model}.`); +} +addFeature(supercar, "turbo"); + +console.log("Features:"); \ No newline at end of file