From afeef94b8c543feba17b5d3bffb3c298d2848538 Mon Sep 17 00:00:00 2001 From: ABDIKARIIN ABDULE Date: Thu, 20 Nov 2025 18:36:12 +0000 Subject: [PATCH] myHomeWOrk 3 js Files --- .DS_Store | Bin 0 -> 6148 bytes arrays.js | 52 +++++++++++++++++++++++++++++++++++++++++++- callbacks.js | 42 ++++++++++++++++++++++++++++++++++++ index.html | 3 +++ objects.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..640508f96361d56d46aec692e9b0bffb85319e70 GIT binary patch literal 6148 zcmeHKF;2r!47E#!NGu&0{|S(KgHIK9P%nT=rGV5b9m<}KfsLzh0XBBTfq1q*C{a{K z26&eIU%u^^pS&TCMMRemn}x_+L~6L9JlZlf%bQPZRw5Np?H=29vAXSc`$^^TfN?81 zmsalOFy?<;4|BV&Y1Z3rjadEs{_^zNzFmy-n;-N0yTP-~u0W+x0V+TRr~noCmkOX~ zo7Ja*T&VyRpaS0t*!Lm94RgUh&_5kmd;|d6Z@e3>eU< p.name === playerName); + + if (player) { + + player.score += scoreToAdd; + } else { + topScorers.push({ name: playerName, score: scoreToAdd }); + } +} + +function printLeaderboard() { + + const sorted = [...topScorers].sort((a, b) => b.score - a.score); + + console.log("🏆 Leaderboard:"); + sorted.forEach((player, index) => { + console.log(`${index + 1}. ${player.name} - ${player.score}`); + }); +} +updateScore("Ronaldo", 1); +updateScore("Neymar",-1); +//printLeaderboard(); +//|----------------|-----------------| diff --git a/callbacks.js b/callbacks.js index 3fadb3f..94d96bc 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,6 +18,17 @@ Expected Output: // ✍️ Solve it here ✍️ +function theCallBackFunction(name) { + console.log(`Welcome, ${name}!`); +} + +function sendMessage(userName, callback) { + callback(userName); +} + +//sendMessage("Amina", theCallBackFunction); + +//|----------------------|----------------------| @@ -49,6 +60,37 @@ Expected Output: // ✍️ Solve it here ✍️ +function theCallBackFunction(temp) { + + if (temp > 30) { + + console.log(`${temp} °C is Hot.`); + + } else if (temp >= 15 && temp <= 30) { + + console.log(`${temp} °C is Warm.`); + + } else { + + console.log(`${temp} °C is Cold.`); + + } +} + +function checkTemperature(temperature, callback) { + + callback(temperature); +} + +//checkTemperature(35 ,theCallBackFunction); + +//checkTemperature(22 ,theCallBackFunction); + +//checkTemperature(10 ,theCallBackFunction); + +//|-----------|----------------------------| + + /* diff --git a/index.html b/index.html index 1104b64..a9e903e 100644 --- a/index.html +++ b/index.html @@ -5,5 +5,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..bfb3f26 100644 --- a/objects.js +++ b/objects.js @@ -31,6 +31,25 @@ 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); + + /* Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗 @@ -64,6 +83,27 @@ Expected Output: // ✍️ Solve it here ✍️ +// 1. Create the dress object +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); /* @@ -104,3 +144,23 @@ Features: */ // ✍️ Solve it here ✍️ + +const supercar = { + model: "Ferrari SF90", + price: 500000, + features: { + color: "Red" + } +}; + +function addFeature(car, featureName) { + car.features[featureName] = true; + console.log(`${featureName.charAt(0).toUpperCase() + featureName.slice(1)} has been added to ${car.model}.`); +} + +addFeature(supercar, "turbo"); + +console.log("Features:"); +for (const feature in supercar.features) { + console.log(`- ${feature}: ${supercar.features[feature]}`); +}