From 29fd0fa200d2f2c37f76511324b1e94c2e5b9df1 Mon Sep 17 00:00:00 2001 From: Abdikadir M Ali Date: Tue, 25 Nov 2025 01:20:20 +0100 Subject: [PATCH] finished --- arrays.js | 56 +++++++++++++++++++++++++++++++++++++++ callbacks.js | 39 ++++++++++++++++++++++++++- index.html | 4 ++- objects.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+), 2 deletions(-) diff --git a/arrays.js b/arrays.js index 37faed2..27e7a54 100644 --- a/arrays.js +++ b/arrays.js @@ -17,7 +17,13 @@ Expected Output: // ✍️ Solve it here ✍️ +const inventory = ["Aple", "Bread", "Milk" , "Eggs"]; +inventory.push ("Orange" , "Bananas"); + +inventory.shift(); + +console.log ("Updated inventory" , inventory) /* @@ -41,8 +47,21 @@ 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")); /* @@ -67,8 +86,45 @@ Output: Sorted leaderboard with updated scores // ✍️ Write your functions here ✍️ +const topScorers = [ + + { name: "Messi", score: 5 }, + + { name: "Ronaldo", score: 3 }, + + { name: "Neymar", score: 4 } +]; + +function updateScore(playerName, scoreToAdd) { + + const player = topScorers.find(p => p.name === playerName); + + if (player) { + + player.score += scoreToAdd; + + } else { + + topScorers.push({ name: playerName, score: scoreToAdd }); + } +} + +function printLeaderboard() { + + const sortedLeaderboard = [...topScorers].sort((a, b) => b.score - a.score); + + console.log("Leaderboard:"); + + sortedLeaderboard.forEach((p, i) => { + console.log(`${i + 1}. ${p.name} — ${p.score}`); + + }); +} +printLeaderboard(); + + diff --git a/callbacks.js b/callbacks.js index 3fadb3f..f4c3161 100644 --- a/callbacks.js +++ b/callbacks.js @@ -19,8 +19,20 @@ Expected Output: // ✍️ Solve it here ✍️ +function theCallBackFunction(name) { + + console.log(`Welcome, ${name}`); +} +function sendMessage (userName, callback) { + + callback(userName); +} + + +sendMessage("Amina", theCallBackFunction); + /* Task 2: Temperature Checker 🌡️🌡️🌡️🌡️ @@ -48,7 +60,32 @@ Expected Output: // ✍️ Solve it here ✍️ - +function checkTemperature(temperature, callback) { + + callback(temperature); +} + +function temperatureMessage(temperature) { + + if (temperature > 30) { + + console.log(`${temperature} is hot`); + } + else if (temperature > 15 & temperature < 30) { + + console.log(`${temperature} is warm`); + } + else { + + console.log(`${temperature} is cold`); + } +} + +checkTemperature(35, temperatureMessage); + +checkTemperature(22, temperatureMessage); + +checkTemperature(10, temperatureMessage); /* diff --git a/index.html b/index.html index 1104b64..698f139 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..74cc970 100644 --- a/objects.js +++ b/objects.js @@ -30,6 +30,33 @@ Expected Output: // ✍️ Solve it here ✍️ +const gamerProfile = { + + username: "ShadowSlayer", + + level: 5, + + isOnline: false +}; + + +function 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); /* @@ -64,8 +91,28 @@ Expected Output: // ✍️ Solve it here ✍️ +const dress = { + + name: "Evening Gown", + + 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); /* Task 3: Supercar Feature Adder 🚗 🚗 🚗 🚗 @@ -104,3 +151,30 @@ 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.charAt(0).toUpperCase() + featureName.slice(1)} has been added to ${supercar.model}.`); +} +addFeature(supercar,"turbo"); + +console.log("features:"); + +for (let feature in supercar.feature) { + + console.log('${feature}: ${supercar.feartures[festure]}'); +} \ No newline at end of file