diff --git a/arrays.js b/arrays.js index 37faed2..075dba4 100644 --- a/arrays.js +++ b/arrays.js @@ -15,6 +15,9 @@ Expected Output: */ // ✍️ Solve it here ✍️ +inventory.push("Oranges", "Bananas"); +inventory.shift(); +console.log(inventory); @@ -39,6 +42,14 @@ Output: "Ali is present." */ // ✍️ Write your function here ✍️ +function isPresent(name) { + if (students.includes(name)) { + return `${name} is present.`; + } else { + return `${name} is absent.`; + } +} + @@ -66,6 +77,28 @@ Output: Sorted leaderboard with updated scores */ // ✍️ Write your functions here ✍️ +function updateScore(playerName, scoreToAdd) { + + const player = topScorers.find(p => p.name === playerName); + + if (player) { + + player.score += scoreToAdd; + } else { + + topScorers.push({ name: playerName, score: scoreToAdd }); + } +} + +function printLeaderboard() { + + const sorte = topScorers.sort((b, t) => b.score - t.score); + + console.log("Top Scorers Leaderboard:"); + sorte.forEach((player, index) => { + console.log(`${index + 1}. ${player.name} - ${player.score}`); + }); +} diff --git a/callbacks.js b/callbacks.js index 3fadb3f..f8e5cb0 100644 --- a/callbacks.js +++ b/callbacks.js @@ -17,6 +17,15 @@ Expected Output: */ // ✍️ Solve it here ✍️ +function theCallBackFunction(name) { + console.log(`Welcome, ${name}!`); +} + + +function sendMessage(userName, callback) { + + callback(userName); +} @@ -47,6 +56,21 @@ 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(temperature, callback) { + + callback(temperature); +} @@ -73,3 +97,18 @@ Expected Output: */ // ✍️ Solve it here ✍️ +function theCallBackFunction(userAnswer, correctAnswer) { + if (userAnswer === correctAnswer) { + console.log("Correct!"); + } else { + console.log(`Incorrect. The correct answer is ${correctAnswer}.`); + } +} + + +function evaluateAnswer(question, correctAnswer, callback) { + + const userAnswer = prompt(question); + callback(userAnswer, correctAnswer); +} + diff --git a/index.html b/index.html index 1104b64..5b38cf4 100644 --- a/index.html +++ b/index.html @@ -5,5 +5,9 @@