Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ Expected Output:
// ✍️ Solve it here ✍️


const inventory = ["Apples", "Bread", "Milk", "Eggs"];

inventory.push("Oranges", "Bananas");
inventory.shift();

console.log("Updated inventory:", inventory);


/*
Expand All @@ -41,7 +46,15 @@ Output: "Ali is present."
// ✍️ Write your function here ✍️


const students = ["Ali", "Fatima", "Hassan", "Layla"];

function isPresent(name) {
if (students.includes(name)) {
return `${name} is present.`;
} else {
return `${name} is absent.`;
}
}



Expand All @@ -67,7 +80,33 @@ 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) {
let playerFound = false;
for (let i = 0; i < topScorers.length; i++) {
if (topScorers[i].name === playerName) {
topScorers[i].score += scoreToAdd;
playerFound = true;
break;
}
}
if (!playerFound) {
topScorers.push({ name: playerName, score: scoreToAdd });
}
}

function printLeaderboard() {
topScorers.sort((a, b) => b.score - a.score);
console.log("Top Scorers Leaderboard:");
topScorers.forEach(player => {
console.log(`${player.name}: ${player.score}`);
});
}



Expand Down
42 changes: 42 additions & 0 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ Expected Output:

// ✍️ Solve it here ✍️

function welcomeCallback(name) {
console.log(`Welcome, ${name}!`);
}

function sendMessage(userName, callback) {
callback(userName);
}


/*
Expand Down Expand Up @@ -49,7 +55,19 @@ Expected Output:
// ✍️ Solve it here ✍️


function evaluateTemperature(temperature) {
if (temperature > 30) {
console.log(`${temperature}°C is Hot.`);
} else if (temperature >= 15 && temperature <= 30) {
console.log(`${temperature}°C is Warm.`);
} else {
console.log(`${temperature}°C is Cold.`);
}
}

function checkTemperature(temperatureValue, callback) {
callback(temperatureValue);
}

/*
STRETCH: Task 3: Quiz Evaluator 📚📚📚📚
Expand All @@ -73,3 +91,27 @@ Expected Output:
*/

// ✍️ Solve it here ✍️
function evaluateQuizAnswer(question, correctAnswer, userAnswer) {
if (userAnswer === correctAnswer) {
console.log("Correct!");
} else {
console.log(`Incorrect. The correct answer is ${correctAnswer}.`);
}
}

function evaluateAnswer(question, correctAnswer, callback) {
// The problem description implies a user's answer needs to be passed to the callback.
// Since there's no mechanism for user input in this context,
// I'll demonstrate with two hardcoded user answers as per the example.
// In a real scenario, 'userAnswer' would come from actual user interaction.

// Example for correct answer
const userAnswerCorrect = "10";
console.log(`Question: ${question}`); // Added to clarify output
callback(question, correctAnswer, userAnswerCorrect);

// Example for incorrect answer
const userAnswerIncorrect = "15";
console.log(`Question: ${question}`); // Added to clarify output
callback(question, correctAnswer, userAnswerIncorrect);
}
44 changes: 44 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,20 @@ Expected Output:

// ✍️ Solve it here ✍️

const gamerProfile = {
username: "ShadowSlayer",
level: 5,
isOnline: false
};

function updateOnlineStatus(profile, status) {
profile.isOnline = status;
if (profile.isOnline) {
console.log(`${profile.username} is now online.`);
} else {
console.log(`${profile.username} is now offline.`);
}
}

/*
Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗
Expand Down Expand Up @@ -64,7 +77,19 @@ Expected Output:

// ✍️ Solve it here ✍️

const dress = {
name: "Evening Gown",
size: "M",
inStock: true
};

function checkAvailability(dressObject) {
if (dressObject.inStock) {
console.log(`${dressObject.name} is available in size ${dressObject.size}.`);
} else {
console.log(`${dressObject.name} is out of stock.`);
}
}

/*
Task 3: Supercar Feature Adder 🚗 🚗 🚗 🚗
Expand Down Expand Up @@ -104,3 +129,22 @@ Features:
*/

// ✍️ Solve it here ✍️
const supercar = {
model: "Ferrari SF90",
price: 500000,
features: {
color: "Red"
}
};

function addFeature(car, featureName) {
car.features[featureName] = true;
console.log(`${featureName} has been added to ${car.model}.`);
}

// After calling addFeature (e.g., addFeature(supercar, "turbo");)
// Use this loop to print features:
// console.log("Features:");
// for (const feature in supercar.features) {
// console.log(`- ${feature}: ${supercar.features[feature]}`);
// }