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 @@ -16,6 +16,11 @@ Expected Output:

// ✍️ Solve it here ✍️

const inventory = ["Apples", "Bread", "Milk", "Eggs"];
inventory.push("Oranges", "Bananas");
inventory.shift();
console.log("Updated inventory:", inventory);




Expand All @@ -39,6 +44,18 @@ 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("Ali"));





Expand Down Expand Up @@ -67,6 +84,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 sortedLeaderboard = topScorers.slice().sort((a, b) => b.score - a.score);
console.log("Leaderboard:");
sortedLeaderboard.forEach(player => {
console.log(`${player.name}: ${player.score}`);
});
}
const topScorers = [
{ name: "Messi", score: 5 },
{ name: "Ronaldo", score: 3 },
{ name: "Neymar", score: 4 }
];
updateScore("Ronaldo", 2);
printLeaderboard();



Expand Down
27 changes: 27 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 sendMessage(name, callback) {
callback(name);
}
function welcomeMessage(name) {
console.log(`Welcome, ${name}!`);
}
sendMessage("Amina", welcomeMessage);


/*



Expand Down Expand Up @@ -48,6 +58,23 @@ Expected Output:

// ✍️ Solve it here ✍️

function checkTemperature(temperature, callback) {
callback(temperature);
}
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.`);
}
}
checkTemperature(35, evaluateTemperature);
checkTemperature(22, evaluateTemperature);
checkTemperature(10, evaluateTemperature);





Expand Down
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<head>Week 5 Assignment</head>
<body>
<h1>Look at the console to see the results</h1>

<script src="arrays.js"></script>
<script src="callbacks.js"></script>
<scripts src="objects.js"></script>
<!-- Before starting, add the javascript files in this html fie -->
</body>
</html>
32 changes: 32 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ Expected Output:

// ✍️ Solve it here ✍️

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

1
console.log(`${gamerProfile.username} is now offline.`);
}
}
const gamerProfile = {
username: "ShadowSlayer",
level: 5,
isOnline: false
};
updateOnlineStatus(gamerProfile, true);





/*
Expand Down Expand Up @@ -64,7 +83,20 @@ Expected Output:

// ✍️ Solve it here ✍️

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.`);
}
}








/*
Task 3: Supercar Feature Adder 🚗 🚗 🚗 🚗
Expand Down