From 974b836136771206264cd02bc867bce6d43f036c Mon Sep 17 00:00:00 2001 From: AHMED-M3 Date: Sat, 6 Dec 2025 09:26:50 +0300 Subject: [PATCH] finished --- arrays.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++- callbacks.js | 38 +++++++++++++++++++++++++++++++++++++ index.html | 4 ++++ objects.js | 47 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 140 insertions(+), 2 deletions(-) diff --git a/arrays.js b/arrays.js index 37faed2..0ff82ce 100644 --- a/arrays.js +++ b/arrays.js @@ -16,6 +16,13 @@ Expected Output: // ✍️ Solve it here ✍️ +const inventory =["milk", "apple","chocolate","bread","eggs"] + + inventory:push("orange","bananas"); + + inventory:finish(); + + console.log("Updated inventory",inventory) @@ -39,7 +46,17 @@ Output: "Ali is present." */ // ✍️ Write your function here ✍️ + const students = ["ahmed","ayaan","nimco","hassan"]; + function isPresent(name){ + if(students.includes(name)){ + return `${name} is present`; + }else{ + return `${name} is absent`; + } + } + console.log(students("nimco")); + console.log(student("ahmed")) @@ -66,7 +83,41 @@ Output: Sorted leaderboard with updated scores */ // ✍️ Write your functions here ✍️ - + + const topScorers = [ + {name: "messi", score: 10}, + {name:"Ronaldo", score: 8}, + {name: "Naymer", score: 6}, + ] + + function updateScore(playerName, points) { + let found = false; + + for (let i = 0; i < topScorers.length; i++) { + if (topScorers[i].name === playerName) { + topScorers[i].score += points; + found = true; + break; + } + } + if (!found) { + topScorers.push({ name: playerName, score: points }); + } + } + function printLeaderboard(){ + topScorers.sort(function(a,b){ + return b.score - a.score; + }); + } + + for (let i = 0; i < topScorers.length; i++){ + console.log(topScorers[i].name + ":" + topScorers[i].score); + } + + updateScore("Messi", 10) + printLeaderboard(); + + diff --git a/callbacks.js b/callbacks.js index 3fadb3f..c347ced 100644 --- a/callbacks.js +++ b/callbacks.js @@ -19,6 +19,14 @@ Expected Output: // ✍️ Solve it here ✍️ + function showWelcome(name) { + console.log("Welcome, " + name + "!"); + } + function sendMessage(userName, callbackFn) { + callbackFn(userName); +} + sendMessage("Ahmed", showWelcome); + /* @@ -47,6 +55,23 @@ Expected Output: */ // ✍️ Solve it here ✍️ + + function readTemperature(value) { + if (value > 30) { + console.log(value + "°C is Hot."); + } else if (value >= 15 && value <= 30) { + console.log(value + "°C is Warm."); + } else { + console.log(value + "°C is Cold."); + } +} + function checkTemperature(temp, callbackFn) { + callbackFn(temp); +} + + checkTemperature(35, readTemperature); + checkTemperature(22, readTemperature); + checkTemperature(10, readTemperature); @@ -73,3 +98,16 @@ Expected Output: */ // ✍️ Solve it here ✍️ + function checkUserAnswer(userAnswer, rightAnswer) { + if (userAnswer === rightAnswer) { + console.log("Correct!"); + } else { + console.log("Incorrect. The correct answer is " + rightAnswer + "."); + } +} + + function checkUserAnswer(){ + let userInput = prompt(question); + callbackFn(userInput, correctAnswer); + } + diff --git a/index.html b/index.html index 1104b64..d181b9d 100644 --- a/index.html +++ b/index.html @@ -5,5 +5,9 @@

Look at the console to see the results

+ + + + \ No newline at end of file diff --git a/objects.js b/objects.js index e2426e9..93fa7be 100644 --- a/objects.js +++ b/objects.js @@ -29,7 +29,22 @@ Expected Output: */ // ✍️ Solve it here ✍️ - + + const gamerProfile = { + username: "nightHunter", + level: 12, + isOnline: false + } + function updateonlineStatus(profile, status) { + profile.isOnline = status; + + if (status === true) { + console.log(profile.username + " is now online."); + } else { + console.log(profile.username + " is now offline."); + } +} + updateonlineStatus(gamerProfile,true); /* @@ -64,7 +79,20 @@ Expected Output: // ✍️ Solve it here ✍️ +const dress = { + name: "Summer Dress", + size: "L", + inStock: false +}; +function checkAvailability(dressItem) { + if (dressItem.inStock === true) { + console.log(dressItem.name + " is available in size " + dressItem.size + "."); + } else { + console.log(dressItem.name + " is out of stock."); + } +} + checkAvailability(dress); /* Task 3: Supercar Feature Adder 🚗 🚗 🚗 🚗 @@ -104,3 +132,20 @@ Features: */ // ✍️ Solve it here ✍️ + + const supercar = { + model: "Lambo V12", + price: 450000, + features: { + color: "Black" + } +}; + function addFeature(car, featureName) { + car.features[featureName] = true; + console.log(featureName + " has been added to " + car.model + "."); +} +addFeature(supercar, "spoiler"); +console.log("Features:"); +for (let item in supercar.features) { + console.log("- " + item + ": " + supercar.features[item]); +}