From c9822832ae04b52a684e1d4cca63e66fdd41b753 Mon Sep 17 00:00:00 2001 From: omarHashi Date: Sun, 13 Jul 2025 21:36:08 +0300 Subject: [PATCH] finished --- arrays.js | 34 +++++++++++++++++++++++++++++++++- callbacks.js | 32 +++++++++++++++++++++++++++++++- index.html | 1 + objects.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 107 insertions(+), 3 deletions(-) diff --git a/arrays.js b/arrays.js index 37faed2..60604d7 100644 --- a/arrays.js +++ b/arrays.js @@ -16,7 +16,10 @@ Expected Output: // ✍️ Solve it here ✍️ - +const inventory = ["Apples", "Bread", "Milk", "Eggs"]; +inventory.push("oranges", "bananas"); +inventory.shift(); +console.log("updated inventory:", inventory); @@ -40,6 +43,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.`; + } +} @@ -67,7 +79,27 @@ 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, addedScore) { + const player=topScorers.find(p=> p.name===playerName); + if (player) { + player.score +=addedScore; + }else { + topScorers.push({name: playerName, score: addedScore}); + } +} +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} goals`); + }) +} diff --git a/callbacks.js b/callbacks.js index 3fadb3f..3055d31 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,7 +18,12 @@ Expected Output: // ✍️ Solve it here ✍️ - +function welcomeMessege(name) { + console.log(`welcome, ${name}!`); +} +function sendMessage(userName, callback) { + callback(userName) +} /* @@ -48,7 +53,19 @@ Expected Output: // ✍️ Solve it here ✍️ +function evaluateTemperature(temp) { + if (temp>30) { + console.log(`${temp}°C is hot.`); + }else if (temp>=15 && temp <=30) { + console.log(`${temp}°C is warm.`); + }else { + console.log(`${temp}°C is cold.`); + } +} +function checkTemperature(tempValue, callback) { + callback(tempValue) +} /* @@ -73,3 +90,16 @@ Expected Output: */ // ✍️ Solve it here ✍️ + +function checkUseranswer(user answer, correctAnswer) { +if (userAnswer===correctAnswer) { + console.log("correct"); +}else { + console.log(`incorect. the correct answer is ${correctAnswer}`); +} + +} +function evaluateAnswer(question, correctAnswer, callback) { + const userAnswe=prompt(question);\ + callback(userAnswer, correctAnswer) +} diff --git a/index.html b/index.html index 1104b64..598da7b 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..4734518 100644 --- a/objects.js +++ b/objects.js @@ -1,4 +1,4 @@ -/* +]/* Task 1: Gamer Profile Manager 🎮 🎮 🎮 🎮 You are creating a system to manage a gamer's profile. @@ -30,7 +30,19 @@ Expected Output: // ✍️ Solve it here ✍️ +const gamerProfile = { + username: "ShadowSlayer", + level: 5, + isOnline: false +}; +function updateOnlineStatus(profile, status) { + if (status) { + console.log(`${profile.username} is now online.`); + }else { + console.log(`${profile.username} is now offline.`); + } +} /* Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗 @@ -64,7 +76,19 @@ 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 of stock.`); + } +} /* 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(car, featureName) { + car.features[featureName]= true; + console.log(`${featureName.charArt(0).toUpperCase()+ featureName.slice(1)} has been added to ${car.model}.`); +} +addFeature(supercar, "turbo"); +console.log("feutures:"); +for (let feature in supercar.features) { + console.log(`- ${feature}: ${supercar.features[feature]}`); +} \ No newline at end of file