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 @@