diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..1d52f2c Binary files /dev/null and b/.DS_Store differ diff --git a/arrays.js b/arrays.js index 37faed2..584d1d9 100644 --- a/arrays.js +++ b/arrays.js @@ -16,8 +16,10 @@ Expected Output: // ✍️ Solve it here ✍️ - - +const inventory = ["Apples", "Bread", "Milk", "Eggs"]; +inventory.push("Oranges", "Bananas") +inventory.shift() +console.log(inventory) /* @@ -40,9 +42,15 @@ 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,10 +75,20 @@ 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) { + for (let i = 0; i < topScorers.length; i++) + if ( topScorers [i].name === playerName && topScorers[i].score === scoreTOAdd) { + return updateScore + } else topScorers.push({name: playerName, score: scoreTOAdd}) +} - - +console.log(topScorers) /* diff --git a/callbacks.js b/callbacks.js index 3fadb3f..888a4a9 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,13 +18,18 @@ Expected Output: // ✍️ Solve it here ✍️ - + function sendMessage(userName, cb) { + return cb (userName) +} +function theCallBackFunction(userName){ + console.log(`Welcome ${userName}`) +} +sendMessage("Amina", theCallBackFunction) /* Task 2: Temperature Checker 🌡️🌡️🌡️🌡️ - You are creating a temperature monitoring system. Write a function called `checkTemperature` that: 1. Takes a temperature value and a callback function as arguments. 2. The callback function should evaluate whether the temperature is "Hot", "Warm", or "Cold" based on the following: @@ -48,6 +53,24 @@ Expected Output: // ✍️ Solve it here ✍️ +function checkTemperature(tempretureValue, cb){ + return cb(tempretureValue) +} + +function theCallBackFunction(tempretureValue){ + if(tempretureValue >= 30){ + console.log(`${tempretureValue}°C is hot`) + } else if(tempretureValue >= 15 && tempretureValue <= 30) { + console.log(`${tempretureValue}°C is Warm`) + } else if(tempretureValue <= 15) { + console.log(`${tempretureValue}°C is cold`) + } else { + console.log("put the tempreture value here") + } + +} + +checkTemperature(10, theCallBackFunction) diff --git a/index.html b/index.html index 1104b64..1201b94 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,9 @@
Week 5 Assignment