From 02dd916593d52e3c8362691468e39a73f1e8b847 Mon Sep 17 00:00:00 2001 From: amiin5377-amo Date: Fri, 21 Nov 2025 19:03:04 +0100 Subject: [PATCH] finished task --- .vscode/launch.json | 15 +++++++++++++++ arrays.js | 40 +++++++++++++++++++++++++++++++++++++--- callbacks.js | 28 +++++++++++++++++++++++----- index.html | 3 +++ objects.js | 35 ++++++++++++++++++++++++++++++----- 5 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2ba986f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/arrays.js b/arrays.js index 37faed2..7e99942 100644 --- a/arrays.js +++ b/arrays.js @@ -17,6 +17,11 @@ Expected Output: // ✍️ Solve it here ✍️ +const inventory = ["Apples", "Bread", "Milk", "Eggs"]; +inventory.push("Oranges" , "Bananas") +inventory.shift() +console.log(inventory) + @@ -40,10 +45,19 @@ Output: "Ali is present." // ✍️ Write your function here ✍️ +const students = ["Ali", "Fatima", "Hassan", "Layla"]; +const isPresent = (name) => { + if(students.includes(name)) { +return `${name} is present` + } + else { + return `${name} is absent` + } - - +} +console.log(isPresent("Ali")) +console.log(isPresent("Mohammed")) /* Task 3: Top Scorers Leaderboard 🏆⚽ @@ -67,7 +81,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 } +]; +const updateScore = (playerName , goalScore) => { + for (let i = 0; i <= topScorers.length; i++) { + if (topScorers[i].name === playerName) { +return score + goalScore + } + else { + topScorers.push( {name: playerName, score: goalScore} ) + } +} +} +const printLeaderboard = () => { + const sorted = topScorers.reverse() + console.log(sorted) +} +updateScore("Neymar" , 2) +printLeaderboard() diff --git a/callbacks.js b/callbacks.js index 3fadb3f..0dddedf 100644 --- a/callbacks.js +++ b/callbacks.js @@ -18,9 +18,14 @@ Expected Output: // ✍️ Solve it here ✍️ - - - +const sendMessage = (userName, cb ) => { +return cb(userName) +} + +const theCallBackFunction = (userName) => { + console.log(`Welcome, ${userName}`) +} +sendMessage("Amina", theCallBackFunction); /* Task 2: Temperature Checker 🌡️🌡️🌡️🌡️ @@ -49,8 +54,21 @@ Expected Output: // ✍️ Solve it here ✍️ - - +const checkTemperature = (tempvalue, cb) => { +return cb (tempvalue) +} + const callbackFunction = (tempvalue) => { + if (tempvalue > 30) { + console.log(`${tempvalue} is Hot `) + } + else if (tempvalue >= 15 && tempvalue <= 30 ) { + console.log(`${tempvalue} is warm `) + } + else { + console.log(`${tempvalue} is warm `) + } + } +checkTemperature(35, callbackFunction) /* STRETCH: Task 3: Quiz Evaluator 📚📚📚📚 diff --git a/index.html b/index.html index 1104b64..7f81608 100644 --- a/index.html +++ b/index.html @@ -5,5 +5,8 @@

Look at the console to see the results

+ + + \ No newline at end of file diff --git a/objects.js b/objects.js index e2426e9..b7abb89 100644 --- a/objects.js +++ b/objects.js @@ -29,9 +29,22 @@ Expected Output: */ // ✍️ Solve it here ✍️ - - - +const gamerProfile = { + username: "ShadowSlayer", + level: 5, + isOnline: false, + +}; +const updateOnlineStatus = (gamerProfile, status) => { +if(status) { + console.log(`${gamerProfile.username} is now online`) +} +else { + console.log(`${gamerProfile.username} is offline`) +} + } +updateOnlineStatus(gamerProfile, true) + /* Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗 @@ -63,8 +76,20 @@ Expected Output: */ // ✍️ Solve it here ✍️ - - +const dress = { + name: "Evening Gown", + size: "M", + inStock: true +}; +const checkAvailability = (dress) => { + if(dress.inStock) { + console.log(`${dress.name} is available in size ${dress.size}.`) + } + else { + console.log(`${dress.name} is not available in size ${dress.size}.`) + } +} +checkAvailability(dress); /* Task 3: Supercar Feature Adder 🚗 🚗 🚗 🚗