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

Look at the console to see the results

+ + + diff --git a/objects.js b/objects.js index e2426e9..8885928 100644 --- a/objects.js +++ b/objects.js @@ -30,6 +30,19 @@ Expected Output: // ✍️ Solve it here ✍️ +const gamerProfile = { + username: "ShadowSlayer", + level: 5, + isOnline: false, +updateOnlineStatus: function(gamerStatus){ + if(gamerStatus === true) + return `${this.username} is now online.` + else{ + return `${this.username} is now absent` + } + } +}; +console.log(gamerProfile.updateOnlineStatus(true)) /* @@ -64,6 +77,20 @@ Expected Output: // ✍️ Solve it here ✍️ + const dress = { + name: "Evening Gown", + size: "M", + inStock: true, +checkAvailability: function(dressAvailability){ + if(dressAvailability === true) + return`${this.name} is available in size ${this.size}` +else{ + return `${this.name} is not available in size ${this.size}` +} +} +} +console.log(dress.checkAvailability(true)) + /* @@ -104,3 +131,23 @@ Features: */ // ✍️ Solve it here ✍️ + +const supercar = { + model: "Ferrari SF90", + price: 500000, + features: { + color: "Red", + } +}; + +function addFeature(supercar,featureName){ + supercar.features[featureName] = true + console.log(`${featureName} has been added to ${supercar.model}`) +} + +for (let key in supercar.features){ + console.log(`${key}: ${supercar.features[key]}`) +} + +addFeature(supercar, "turbo") +