From 088916698d4841bb99fe82e802d71dc3f52a63a5 Mon Sep 17 00:00:00 2001 From: mukhtaarbatuun Date: Fri, 21 Nov 2025 19:06:30 +0100 Subject: [PATCH] Finished --- "akjla\303\266dsfdsfkaj" | 27 +++++++++++++++++ arrays.js | 53 ++++++++++++++++++++++++++++----- callbacks.js | 33 +++++++++++++++++++-- index.html | 4 ++- objects.js | 63 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 169 insertions(+), 11 deletions(-) create mode 100644 "akjla\303\266dsfdsfkaj" diff --git "a/akjla\303\266dsfdsfkaj" "b/akjla\303\266dsfdsfkaj" new file mode 100644 index 0000000..0559d55 --- /dev/null +++ "b/akjla\303\266dsfdsfkaj" @@ -0,0 +1,27 @@ +diff.astextplain.textconv=astextplain +filter.lfs.clean=git-lfs clean -- %f +filter.lfs.smudge=git-lfs smudge -- %f +filter.lfs.process=git-lfs filter-process +filter.lfs.required=true +http.sslbackend=schannel +core.autocrlf=true +core.fscache=true +core.symlinks=false +pull.rebase=false +credential.helper=manager +credential.https://dev.azure.com.usehttppath=true +init.defaultbranch=master +user.name=mukhtaarbatuun +user.email=mukhtaarbatuun1@gmail.com +core.repositoryformatversion=0 +core.filemode=false +core.bare=false +core.logallrefupdates=true +core.symlinks=false +core.ignorecase=true +remote.origin.url=https://github.com/gabischool/Week5_JS_Assignment.git +remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* +branch.main.remote=origin +branch.main.merge=refs/heads/main +branch.main.vscode-merge-base=origin/main +branch.mukhtaarbatuun.vscode-merge-base=origin/main diff --git a/arrays.js b/arrays.js index 37faed2..1b741a3 100644 --- a/arrays.js +++ b/arrays.js @@ -16,8 +16,10 @@ Expected Output: // ✍️ Solve it here ✍️ - - +const inventory = ["Apples", "Bread", "Milk", "Eggs"]; +inventory.push("Oranges" , "Bananas"); +inventory.shift(); +console.log(inventory); /* @@ -40,11 +42,19 @@ Output: "Ali is present." // ✍️ Write your function here ✍️ - - - - - +const students = ["Ali", "Fatima", "Hassan", "Layla"]; +function isPresent (studentName) { +if (students.includes(studentName)){ + return`${studentName} is present.`; +} +else { + return `${studentName} is absent.`; +} +} + +console.log(isPresent("Ali")); +console.log(isPresent("Ahmed")); +console.log(isPresent("Hassan")); /* Task 3: Top Scorers Leaderboard 🏆⚽ @@ -69,6 +79,35 @@ Output: Sorted leaderboard with updated scores +const topScorers = [ + { name: "Messi", score: 5 }, + { name: "Ronaldo", score: 3 }, + { name: "Neymar", score: 4 } +]; + +const updateScore = (playerName, goalScore) => { +const player = topScorers.find(scorer => scorer.name === playerName); +if (player) { + player.score += goalScore; + } else { + topScorers.push({ name: playerName, score: goalScore }); + } +}; +const printLeaderboard = () => { + const sortedLeaderboard = [...topScorers]; + sortedLeaderboard.sort((a, b) => b.score - a.score); + + console.log("Top Scorers Leaderboard:"); + sortedLeaderboard.forEach((scorer, index) => { + console.log(`${index + 1}. ${scorer.name}: ${scorer.score}`); + }); +}; + +printLeaderboard(); +updateScore("Ronaldo", 2); +printLeaderboard(); + + diff --git a/callbacks.js b/callbacks.js index 3fadb3f..0cce789 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,9 +18,14 @@ Expected Output: // ✍️ Solve it here ✍️ - - - +function welcomemessage(name){ +console.log(`welcome, ${name}!`); +} +function sendMessage(name , callback) { + callback(name); +} + +sendMessage("Amina" , welcomemessage) /* Task 2: Temperature Checker 🌡️🌡️🌡️🌡️ @@ -48,6 +53,28 @@ Expected Output: // ✍️ Solve it here ✍️ +const evaluateTemperature =(temperature) => { + let status; + if (temperature > 30) { + console.log(`${temperature}°C is Hot.`) + } else if (temperature >= 15 && temperature<= 30) { + console.log(`${temperature}°C is Warm.`) + } else + { + console.log(`${temperature}°C is Cold.`) + } + + +}; + +const checkTemperature = (temperature, callback) => { + callback(temperature); +}; + +checkTemperature(35, evaluateTemperature); +checkTemperature(22, evaluateTemperature); +checkTemperature(10, evaluateTemperature); + diff --git a/index.html b/index.html index 1104b64..a7e5edb 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,8 @@

Look at the console to see the results

- + + + \ No newline at end of file diff --git a/objects.js b/objects.js index e2426e9..cdb3431 100644 --- a/objects.js +++ b/objects.js @@ -32,6 +32,32 @@ Expected Output: + +const gamerProfile = { + username: "ShadowSlayer", + level: 5, + isOnline: false +}; +const updateOnlineStatus = (profile, status) => { + profile.isOnline = status; + + if (status) { + console.log(`${profile.username} is now online.`); + } else { + console.log(`${profile.username} is now offline.`); + } +}; + + + +updateOnlineStatus(gamerProfile, true); + + + + + + + /* Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗 @@ -64,6 +90,23 @@ Expected Output: // ✍️ Solve it here ✍️ +const dress = { + name: "Evening Gown", + size: "M", + inStock: true +}; + +const checkAvailability = (dressItem) => { + if (dressItem.inStock) { + console.log(`${dressItem.name} is available in size ${dressItem.size}.`); + } else { + console.log(`${dressItem.name} is out of stock.`); + } +}; + +checkAvailability(dress) + + /* @@ -104,3 +147,23 @@ Features: */ // ✍️ Solve it here ✍️ + +const supercar = { + model: "Ferrari SF90", + price: 500000, + features: { + color: "Red" + } +}; + +const addFeature= (car , featureName) => { + car.features[featureName]=true; + console.log(`${featureName} has been added to ${car.model}.`); +}; + +addFeature(supercar, "turbo"); + +console.log("Features:"); +for (let feature in supercar.features) { + console.log(`- ${feature}: ${supercar.features[feature]}`); +} \ No newline at end of file