diff --git a/arrays.js b/arrays.js index 37faed2..28a9442 100644 --- a/arrays.js +++ b/arrays.js @@ -15,8 +15,15 @@ Expected Output: */ // ✍️ Solve it here ✍️ +let inventory = ["Apples", "Bread", "Milk", "Eggs"]; +console.log(inventory); +inventory.push("orange", "banana") +console.log(inventory) +inventory.shift() +console.log(inventory) +// i done @@ -40,9 +47,13 @@ Output: "Ali is present." // ✍️ Write your function here ✍️ - - - +const student = ["Ali", "Fatima", "Hassan", "Layla"]; +function isPresent (studentsName){ +if(student.includes(studentsName)){ + return `${studentsName} is present` +} else return `${studentsName} is absent` +} +console.log(isPresent("Hassan")); /* @@ -50,7 +61,8 @@ Task 3: Top Scorers Leaderboard 🏆⚽ You are creating a leaderboard for a soccer game. The array `topScorers` contains the names of players and their scores. -1. Write a function called `updateScore` that takes a player's name and a score to add. If the player exists in the leaderboard, add the score to their total. If not, add the player to the array with the given score. +1. Write a function called `updateScore` that takes a player's name and a score to add. If the player exists in the leaderboard, + add the score to their total. If not, add the player to the array with the given score. 2. Write another function called `printLeaderboard` that sorts the leaderboard in descending order of scores and prints it. Array: @@ -67,7 +79,16 @@ Output: Sorted leaderboard with updated scores // ✍️ Write your functions here ✍️ - +const topScorers = [ + {name: "Abdi", score: 8}, + {name: "Duraan", score:10}, + {name:"Ahmed", score:6} +]; +function printLeaderboard (){ + return `${topScorers} Sorted leaderboard with updated scores`; +} +console.log(printLeaderboard("Abdi", 2)); +// this i confuse @@ -138,4 +159,4 @@ Final Output: - "The treasure remains hidden. Try again!" (if danger is encountered) - "Congratulations! You found the ultimate treasure!" (if all conditions are met) -*/ +*/ \ No newline at end of file diff --git a/callbacks.js b/callbacks.js index 3fadb3f..cb49654 100644 --- a/callbacks.js +++ b/callbacks.js @@ -16,9 +16,15 @@ Expected Output: - "Welcome, Amina!" */ -// ✍️ Solve it here ✍️ - +// ✍️ Solve it here ✍️f +function sendMessage (callback, userName){ + return callback(userName) +} +function message (userName){ + console.log(` wellcome ${userName} `) +} +sendMessage(message, "Amina") /* @@ -48,6 +54,21 @@ Expected Output: // ✍️ Solve it here ✍️ +function checkTemperature (tep, callback){ + return callback(tep) +} +function evaluate (tep){ + if(tep==30){ + console.log(`the temperature is Hot`) + } else if (tep===22){ + console.log(`the temperature is warm`) + } else if (tep===10){ + console.log(`the temperature is cold`) + } else { + console.log(`please select 30-10`) + } +} +checkTemperature(30, evaluate); diff --git a/index.html b/index.html index 1104b64..ce27378 100644 --- a/index.html +++ b/index.html @@ -5,5 +5,8 @@