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
Binary file added .DS_Store
Binary file not shown.
52 changes: 51 additions & 1 deletion arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ Expected Output:

// ✍️ Solve it here ✍️

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

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

inventory.shift();

//console.log(inventory);


/*
Expand All @@ -40,9 +45,20 @@ 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.`;
}
}


//console.log(isPresent("Fatima"));
//console.log(isPresent("Jamac"));
//|_________________________|______________________|


/*
Expand All @@ -67,8 +83,42 @@ Output: Sorted leaderboard with updated scores

// ✍️ Write your functions here ✍️

/*
Task 3: Top Scorers Leaderboard 🏆⚽
*/

const topScorers = [
{ name: "Messi", score: 5 },
{ name: "Ronaldo", score: 3 },
{ name: "Neymar", score: 4 }
];

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 sorted = [...topScorers].sort((a, b) => b.score - a.score);

console.log("🏆 Leaderboard:");
sorted.forEach((player, index) => {
console.log(`${index + 1}. ${player.name} - ${player.score}`);
});
}

updateScore("Ronaldo", 1);
updateScore("Neymar",-1);
//printLeaderboard();

//|----------------|-----------------|



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

// ✍️ Solve it here ✍️

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

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

//sendMessage("Amina", theCallBackFunction);

//|----------------------|----------------------|



Expand Down Expand Up @@ -49,6 +60,37 @@ Expected Output:
// ✍️ Solve it here ✍️


function theCallBackFunction(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);
}

//checkTemperature(35 ,theCallBackFunction);

//checkTemperature(22 ,theCallBackFunction);

//checkTemperature(10 ,theCallBackFunction);

//|-----------|----------------------------|




/*
Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<h1>Look at the console to see the results</h1>

<!-- Before starting, add the javascript files in this html fie -->
<script src="arrays.js"></script>
<script src="callbacks.js"></script>
<script src="objects.js"></script>
</body>
</html>
60 changes: 60 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ 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.`);
}
}

//updateOnlineStatus(gamerProfile, true);



/*
Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗
Expand Down Expand Up @@ -64,6 +83,27 @@ Expected Output:

// ✍️ Solve it here ✍️

// 1. Create the dress object
const dress = {
name: "Evening Gown",
size: "M",
inStock: true
};

function checkAvailability(dress) {

if (dress.inStock) {

console.log(`${dress.name} is available in size ${dress.size}.`);

} else {

console.log(`${dress.name} is out of stock.`);

}
}

//checkAvailability(dress);


/*
Expand Down Expand Up @@ -104,3 +144,23 @@ 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.charAt(0).toUpperCase() + featureName.slice(1)} has been added to ${car.model}.`);
}

addFeature(supercar, "turbo");

console.log("Features:");
for (const feature in supercar.features) {
console.log(`- ${feature}: ${supercar.features[feature]}`);
}