From 053efe59110effdfa3bf29ed9058cfd8010a5c50 Mon Sep 17 00:00:00 2001 From: joseph Date: Sat, 5 Jul 2025 11:10:47 -0400 Subject: [PATCH 1/2] finished --- arrays.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ callbacks.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ objects.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) diff --git a/arrays.js b/arrays.js index 37faed2..724640b 100644 --- a/arrays.js +++ b/arrays.js @@ -16,9 +16,14 @@ Expected Output: // ✍️ Solve it here ✍️ +const inventory = ["Apples", "Bread", "Milk", "Eggs"]; + +inventory.push("Orange","Bannanes", ); +inventory.shift(); +console.log("Uppdated inventory:", inventory); /* Task 2: Student Attendance Checker πŸ“šβœ… @@ -40,6 +45,20 @@ Output: "Ali is present." // ✍️ Write your function here ✍️ +const students = ["Ali", "Fatima", "Hassan", "Layla"]; + +function isPresent(name) { + if(students.includes(name)){ + return `${name} ispresent.`; + else{ + return `${name} is absent.`; + + } + } +} +console.log(isPresent("ali")); + + @@ -68,6 +87,34 @@ 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){ + const player= score.find(p => p.name ===playerName); + if(player) { + player.score += ScoreToadd; + else{ + topScorers.push({name:playerName, score.ScoreToadd}); + + } + + } + +} + +function printLeaderboard() { + const Sorted =[...topScorers]. sort ((a,b )=> b.score - a.score); + console.log("leader board:"); + Sorted.forEach((player, index) => { + console.log(`${index +1}.${player.name} -${player.score}`); + + }); + +} diff --git a/callbacks.js b/callbacks.js index 3fadb3f..fab8019 100644 --- a/callbacks.js +++ b/callbacks.js @@ -17,6 +17,16 @@ Expected Output: */ // ✍️ Solve it here ✍️ +function welcomeMessage(_name){ + console.log(`wellcome{name}!`); +} +function sendMessage(username, callback){ + callback(username); + +} + + +sendMessage("Amina", welcomeMessage); @@ -49,7 +59,30 @@ Expected Output: // ✍️ Solve it here ✍️ +function checkTemperatur(temperature){ + if(temperature > 30){ + console.log(`$ {temp} cΒΊ is hot.`); + }else if(temperature >= 15 && temperature <= 30){ + console.log(`$ {temp} cΒΊ is warm.`); + }else{ + console.log(`${temperature} cΒΊ is cold.`); + + } + + } +function checkTemperatur(temperature, callback){ + callback(temperature); + +} + + + +checkTemperature(35, checkTemperature); +checkTemperature(22,checkTemperature); + + +checkTemperature(10, checkTemperature); /* STRETCH: Task 3: Quiz Evaluator πŸ“šπŸ“šπŸ“šπŸ“š @@ -73,3 +106,22 @@ Expected Output: */ // ✍️ Solve it here ✍️ + +function evaluateAnswer(userAnswer, _correct){ + if(userAnswer === correctAnswer){ + console.log("correct1"); + else{ + console.log (`incorrect. the correct answer is ${correctAnswer}.`); + + } + } +} +function evaluateAnswer(question, correctAnswer, callback){ + const userAnswer = prompt(question); + callback(userAnswer, correctAnswer); +} + + + + +evaluateAnswer("What is 5 + 5?", "10", TheCallBackFunction); diff --git a/objects.js b/objects.js index e2426e9..b3146d9 100644 --- a/objects.js +++ b/objects.js @@ -30,7 +30,24 @@ 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 online.`); + + }else{ + console.log(`${profile.username} is now offline.`); + + } + +} +updateOnlineStatus(gamerProfile, true); /* Task 2: Dress Inventory Checker πŸ‘— πŸ‘— πŸ‘— πŸ‘— πŸ‘— @@ -63,8 +80,22 @@ Expected Output: */ // ✍️ Solve it here ✍️ +const dress={ + name: "Evening Gown", + size: "M" + instock:true +}; +function checkAvailabilit(dress){ + if (dress.instock){ + console.log(`${dress.name} is avilabe in size ${dress.size}.`); + }else { + console.log(`${dress.name}is out of stock.`); + } + +} +checkAvailabilit(dress); /* Task 3: Supercar Feature Adder πŸš— πŸš— πŸš— πŸš— @@ -104,3 +135,17 @@ Features: */ // ✍️ Solve it here ✍️ +const supercar = { + model: "ferrari SF90 ", + price: 500000, + features:{ + color: "Red" + + } + +}; +function addFeature(car, featureName){ + car.features[featureName]= true; + + +} \ No newline at end of file From e4e0148391c1747eba5ae3959c20bf13a0532eca Mon Sep 17 00:00:00 2001 From: joseph Date: Sat, 12 Jul 2025 16:04:57 -0400 Subject: [PATCH 2/2] finishe --- arrays.js | 4 ++++ objects.js | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arrays.js b/arrays.js index 724640b..46eed9e 100644 --- a/arrays.js +++ b/arrays.js @@ -186,3 +186,7 @@ Final Output: - "Congratulations! You found the ultimate treasure!" (if all conditions are met) */ + +function findClue(clues, Map){ + +} diff --git a/objects.js b/objects.js index b3146d9..ef00b86 100644 --- a/objects.js +++ b/objects.js @@ -80,11 +80,12 @@ Expected Output: */ // ✍️ Solve it here ✍️ -const dress={ +const dress = { name: "Evening Gown", - size: "M" - instock:true -}; + size: "M", + inStock: true + }; + function checkAvailabilit(dress){ if (dress.instock){ console.log(`${dress.name} is avilabe in size ${dress.size}.`);