diff --git a/arrays.js b/arrays.js index 37faed2..284176d 100644 --- a/arrays.js +++ b/arrays.js @@ -16,9 +16,16 @@ Expected Output: // ✍️ Solve it here ✍️ +// const inventory = ["Apple", "Bread", "Milk", "Eggs"]; +// inventory.push("Oranges"); +// inventory.push("Bananas"); +// inventory.shift(0); +// const myinventory = inventory.with(4, "Oranges"); + +// console.log(inventory); /* Task 2: Student Attendance Checker πŸ“šβœ… @@ -40,10 +47,17 @@ Output: "Ali is present." // ✍️ Write your function here ✍️ +// const student = ["Ali", "Fatima", "Hassan", "Layla"]; +// function isPresent(name) { +// if (student.includes(name)) { +// return `${name} is present.`; +// } else { +// return `${name} is absent`; +// } +// } - - +// console.log(isPresent("Hassan")); /* Task 3: Top Scorers Leaderboard πŸ†βš½ @@ -67,11 +81,28 @@ 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, scoreToAd) { +// const player = topScorers.find((p) => p.name === playerName); +// if (player) { +// return (player.score += scoreToAd); +// } else { +// topScorers.push({ name: playerName, score: scoreToAd }); +// } +// } + +// 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}`) +// }) /* STRETCH TASK: **The Ultimate Treasure Hunt** πŸ—ΊοΈπŸ’ŽπŸ΄β€β˜ οΈ diff --git a/callbacks.js b/callbacks.js index 3fadb3f..c8862b8 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,15 +18,21 @@ Expected Output: // ✍️ Solve it here ✍️ +// function sendMessage(userName, callback) { +// callback(userName); +// } +// function aniga(name) { +// console.log(`welcome, ${name}!`); +// } +// sendMessage("Amina", aniga); /* 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. +Y1. 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: - "Hot" if the temperature is above 30. - "Warm" if the temperature is between 15Β°C and 30. @@ -43,13 +49,26 @@ checkTemperature(35, theCallBackFunction); Expected Output: - "35Β°C is Hot." - "22Β°C is Warm." -- "10Β°C is Cold." +- "10Β°C is Cold."ou are creating a temperature monitoring system. Write a function called `checkTemperature` that: + */ // ✍️ Solve it here ✍️ - - +// function evaluateTemperature(temperature) { +// if (temperature > 30) { +// console.log(`${temperature}Β°C is hot`); +// } else if (temperature >= 15 && temperature <= 30) { +// console.log(`${temperature}Β°C is warm`); +// } else { +// console.log(`${temperature}Β°C is cold.`); +// } +// } + +// function checkTemperature(temperature, callback) { +// callback(temperature); +// } +// checkTemperature(10, evaluateTemperature); /* STRETCH: Task 3: Quiz Evaluator πŸ“šπŸ“šπŸ“šπŸ“š diff --git a/objects.js b/objects.js index e2426e9..04778c5 100644 --- a/objects.js +++ b/objects.js @@ -30,8 +30,18 @@ Expected Output: // ✍️ Solve it here ✍️ - - +// const gamerProfile = { +// username: "ShadowSlayer", +// level: 5, +// isOnline: false, +// }; + +// function updateOnlineStatus(profile, status) { +// profile.isOnline = status; +// console.log(`${profile.username} is now ${status ? "online" : "offline"}.`); +// } + +// updateOnlineStatus(gamerProfile, true); /* Task 2: Dress Inventory Checker πŸ‘— πŸ‘— πŸ‘— πŸ‘— πŸ‘— @@ -64,7 +74,21 @@ Expected Output: // ✍️ Solve it here ✍️ +// 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 stock.`); +// } +// } + +// checkAvailability(dress); /* Task 3: Supercar Feature Adder πŸš— πŸš— πŸš— πŸš— @@ -104,3 +128,20 @@ 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}`); +// } + +// addFeature(supercar, "turbo"); + +// console.log(supercar);