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
50 changes: 50 additions & 0 deletions arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Expected Output:

// ✍️ Solve it here ✍️

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

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

inventory.shift();

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




Expand All @@ -40,6 +48,21 @@ 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.`;
}
}

// Tusaale:
console.log(isPresent("Ali")); // Ali is present.
console.log(isPresent("Mohamed")); // Mohamed is absent.





Expand Down Expand Up @@ -67,6 +90,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 player = topScorers.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("🏆 Leaderboard:");
sorted.forEach((player, index) => {
console.log(`${index + 1}. ${player.name} - ${player.score} goals`);
});
}

// Tusaale:
updateScore("Ronaldo", 2);
printLeaderboard();




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

// ✍️ Solve it here ✍️

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

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

// Tusaale:
sendMessage("Amina", welcomeMessage); // Output: Welcome, Amina!



Expand Down Expand Up @@ -48,6 +58,24 @@ 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(temp, callback) {
callback(temp);
}

// Tusaalooyin:
checkTemperature(35, evaluateTemperature); // Output: 35°C is Hot.
checkTemperature(22, evaluateTemperature); // Output: 22°C is Warm.
checkTemperature(10, evaluateTemperature); // Output: 10°C is Cold.



Expand Down
66 changes: 66 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ 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.`);
}
}

// Tusaale:
updateOnlineStatus(gamerProfile, true); // Output: ShadowSlayer is now online.
updateOnlineStatus(gamerProfile, false); // Output: ShadowSlayer is now offline.



/*
Expand Down Expand Up @@ -64,6 +84,22 @@ Expected Output:

// ✍️ Solve it here ✍️

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

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

// Tusaale:
checkAvailability(dress); // Output: Evening Gown is available in size M.


/*
Expand Down Expand Up @@ -104,3 +140,33 @@ Features:
*/

// ✍️ Solve it here ✍️

// 1. Create the supercar object
const supercar = {
model: "Ferrari SF90",
price: 500000,
features: {
color: "Red"
}
};

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

console.log("Features:");
for (let key in car.features) {
console.log(`- ${key}: ${car.features[key]}`);
}
}

// Tusaale:
addFeature(supercar, "turbo");
/*
Output:
Turbo has been added to Ferrari SF90.
Features:
- color: Red
- turbo: true
*/