diff --git a/arrays.js b/arrays.js index 37faed2..0148813 100644 --- a/arrays.js +++ b/arrays.js @@ -15,9 +15,12 @@ Expected Output: */ // ✍️ Solve it here ✍️ - - - +/* +const inventory = ["Apples", "Bread", "Milk", "Eggs"] +inventory.push("Oranges","Banana") +inventory.shift() +console.log("Updated inventory" ,inventory) +*/ /* @@ -40,9 +43,22 @@ Output: "Ali is present." // ✍️ Write your function here ✍️ +/* +const students = ["Ali", "Fatima", "Hassan", "Layla"]; + +function isPresent(stdName){ + if(students.includes(stdName)){ + console.log(`${stdName} is present`) + } + else{ + console.log(`${stdName} is absent`) + } +} +isPresent("Ali") +*/ /* @@ -67,11 +83,34 @@ 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) { + let player = topScorers.find(p => p.name === playerName); + if (player) { + player.score = player.score + scoreToAdd; + } else { + topScorers.push({ name: playerName, score: scoreToAdd }); + } +} +function printLeaderboard() { + const sorted = topScorers.sort(function(a, b) { + return b.score - a.score; + }); + console.log("Sorted Leaderboard:"); + console.log(sorted); +} +// Test +updateScore("Haland", 7); +printLeaderboard(); /* STRETCH TASK: **The Ultimate Treasure Hunt** 🗺️💎🏴☠️ diff --git a/callbacks.js b/callbacks.js index 3fadb3f..71c1192 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,7 +18,16 @@ Expected Output: // ✍️ Solve it here ✍️ +function theCallBackFunction(name) { + console.log(`Welcome, ${name} `); +} +function sendMessage(userName, callback) { + callback(userName); +} + +// Test +sendMessage("Amina", theCallBackFunction); /* @@ -48,7 +57,24 @@ Expected Output: // ✍️ Solve it here ✍️ - +function temperatureMessage(temp) { + if (temp > 30) { + console.log(temp + "°C is Hot."); + } else if (temp >= 15) { + console.log(temp + "°C is Warm."); + } else { + console.log(temp + "°C is Cold."); + } +} + +function checkTemperature(value, callback) { + callback(value); +} + +// Tests +checkTemperature(35, temperatureMessage) +checkTemperature(22, temperatureMessage) +checkTemperature(10, temperatureMessage) /* diff --git a/index.html b/index.html index 1104b64..a9e903e 100644 --- a/index.html +++ b/index.html @@ -5,5 +5,8 @@