diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..640508f Binary files /dev/null and b/.DS_Store differ diff --git a/arrays.js b/arrays.js index 37faed2..3bebefd 100644 --- a/arrays.js +++ b/arrays.js @@ -16,8 +16,13 @@ Expected Output: // ✍️ Solve it here ✍️ +const inventory = ["Apples", "Bread", "Milk", "Eggs"]; + +inventory.push("Oranges", "Bananas"); +inventory.shift(); +//console.log(inventory); /* @@ -40,9 +45,20 @@ 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("Fatima")); +//console.log(isPresent("Jamac")); +//|_________________________|______________________| /* @@ -67,8 +83,42 @@ Output: Sorted leaderboard with updated scores // ✍️ Write your functions here ✍️ +/* +Task 3: Top Scorers Leaderboard 🏆⚽ +*/ + +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 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]}`); +}