From c7715504b1cf418e9ec5d524abea8646ed71ddfa Mon Sep 17 00:00:00 2001 From: Ayan Farah Date: Sun, 13 Jul 2025 09:20:02 +0100 Subject: [PATCH] completed --- arrays.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++--- callbacks.js | 44 +++++++++++++++++++++++++++++++++++++++++ index.html | 3 ++- objects.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 4 deletions(-) diff --git a/arrays.js b/arrays.js index 37faed2..5ead586 100644 --- a/arrays.js +++ b/arrays.js @@ -16,10 +16,10 @@ Expected Output: // ✍️ Solve it here ✍️ +let inventory = [ "Bread","Milk","Eggs",]; - - - +inventory.push("Orange","Banana"); +console.log(inventory) /* Task 2: Student Attendance Checker 📚✅ @@ -41,6 +41,19 @@ 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")); + console.log(isPresent("Iqra")); @@ -68,6 +81,42 @@ Output: Sorted leaderboard with updated scores // ✍️ Write your functions here ✍️ +const topScorers = [ + { name: "Messi", score: 5 }, + { name: "Ronaldo", score: 3 }, + { name: "Neymar", score: 5}, + +]; + +function updateScore(name, scoreToAdd) { + let playerFound = false; + + for (let i = 0; i < topScorers.length; i++) { + if (topScorers[i].name === name) { + topScorers[i].score += scoreToAdd; + playerFound = true; + break; + } + } + +if (!playerFound) { + topScorers.push({ name: name, score: scoreToAdd }); + } +} + +// didn`t finnish yet + +function printLeaderboard() { + topScorers.sort((a, b) => b.score - a.score); + + console.log("Top Scorers Leaderboard:"); + for (let player of topScorers) { + console.log(`${player.name}: ${player.score}`); + } +} +updateScore("Ronaldo", 2); +printLeaderboard(); + diff --git a/callbacks.js b/callbacks.js index 3fadb3f..4e4c007 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,6 +18,17 @@ Expected Output: // ✍️ Solve it here ✍️ +// the welcome callback function + +function theCallBackFunction(name) { + console.log(`Welcome, ${name}!`); +} +// sendMessage function + +function sendMessage(userName, callback) { + callback(userName); +} +sendMessage("Amina", theCallBackFunction); @@ -49,6 +60,27 @@ Expected Output: // ✍️ Solve it here ✍️ +// The call back function +function thecallBackFunction(tempreture) { + if (tempreture > 30) { + console.log(`${tempreture}°C is Hot.`); + }else if (tempreture >= 15 && tempreture <= 30) { + console.log(`${tempreture}°C is Warm.`) + }else { + console.log(`${tempreture}`) + } +} + +function checkTemperature(value, callback) { + callback(value); +} + checkTemperature(40, thecallBackFunction) + + + + + + /* @@ -73,3 +105,15 @@ Expected Output: */ // ✍️ Solve it here ✍️ + +function TheCallBackFunction(userAnswer, correctAnswer) { + if (userAnswer === correctAnswer) { + console.log("Correct!"); + } else { + console.log(`Incorrect. The correct answer is ${correctAnswer}.`); + } + } + function evaluateAnswer(question, correctAnswer, callback) { + const userAnswer = prompt(question); + callback(userAnswer, correctAnswer); + } \ No newline at end of file diff --git a/index.html b/index.html index 1104b64..0712513 100644 --- a/index.html +++ b/index.html @@ -5,5 +5,6 @@

Look at the console to see the results

- + + \ No newline at end of file diff --git a/objects.js b/objects.js index e2426e9..70c616f 100644 --- a/objects.js +++ b/objects.js @@ -30,6 +30,28 @@ Expected Output: // ✍️ Solve it here ✍️ +const gamerProfile = { + username: "ShadowSlayer", + level: 5, + isOnline: false +}; + + function updateOnlineStatus(profile,status) { + profile.isOnline = status; + if (status) { + console.log(`${profile.username} is now ononline.`); + } else { + console.log(`${profile.username} is now offline`); + } + } + +updateOnlineStatus(gamerProfile,true); +updateOnlineStatus(gamerProfile, false); + + + + + /* @@ -64,6 +86,21 @@ Expected Output: // ✍️ Solve it here ✍️ +const dress = { + name: "Evening Gown", + size: "M", + inStock: true +}; + +// checkAvailability(dress) { +if (dress.inStock) { + console.log(`${dress.name} is available in size ${dress.size}.`); +}else { + console.log(`${dress.name} is out of stock`) +} + + + /* @@ -104,3 +141,20 @@ Features: */ // ✍️ Solve it here ✍️ + + +//The superCar object + +const supercar = { + model: "Ferrari SF90", + price: 500000, + features: { + color: "Red" + } +}; + +// addFeature Function +function addFeature(Car, featureName) { + Car.feature[featureName] = true; + console.log(`featureName.charAt(0) .toUpperCase() + featureName.slice(1} has been added to $ {car.model})`); +} \ No newline at end of file