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
44 changes: 35 additions & 9 deletions arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Expected Output:
*/

// ✍️ Solve it here ✍️



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


/*
Expand All @@ -39,9 +40,16 @@ Output: "Ali is present."
*/

// ✍️ Write your function here ✍️



const students = ["Ali", "Fatima", "Hassan", "Layla"];
function isPresent(name){
if(name==students.at()){
return `${[name]} is present`;
}
else{
return `${[name]} is not present`;
}
}
console.log(isPresent("Ali"));



Expand All @@ -50,8 +58,10 @@ Task 3: Top Scorers Leaderboard 🏆⚽

You are creating a leaderboard for a soccer game. The array `topScorers` contains the names of players and their scores.

1. Write a function called `updateScore` that takes a player's name and a score to add. If the player exists in the leaderboard, add the score to their total. If not, add the player to the array with the given score.
2. Write another function called `printLeaderboard` that sorts the leaderboard in descending order of scores and prints it.
1. Write a function called `updateScore` that takes a player's name and a score to add. If the player exists in the
leaderboard, add the score to their total. If not, add the player to the array with the given score.
2. Write another function called `printLeaderboard` that sorts the leaderboard in descending order of scores and prints
it.

Array:
const topScorers = [
Expand All @@ -66,7 +76,23 @@ Output: Sorted leaderboard with updated scores
*/

// ✍️ Write your functions here ✍️

const topScorers = [
{ name: "Messi", score: 5 },
{ name: "Ronaldo", score: 3 },
{ name: "Neymar", score: 4 }
]
let i;
function updateScore(name, Score){
if(name==topScorers.at().name){
topScorers.at().score=topScorers.at().score+Score;
}
else{
topScorers.push({name, Score});
}

}
updateScore("Messi", 5);
console.log(topScorers);



Expand Down
24 changes: 22 additions & 2 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ Expected Output:
*/

// ✍️ Solve it here ✍️

function sendMessage(name, callback){
callback(name);
}
function call(names){
console.log(`welcome, ${names}`);
}
sendMessage("Amina", call);



Expand Down Expand Up @@ -47,7 +53,21 @@ Expected Output:
*/

// ✍️ Solve it here ✍️

function checkTemperature(temp, Callback){
Callback(temp);
}
function checkTempcallback(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`);
}
}
checkTemperature(35, checkTempcallback);



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="objects.js"></script>
<script src="callbacks.js"></script>
</body>
</html>
54 changes: 43 additions & 11 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ Expected Output:
*/

// ✍️ Solve it here ✍️

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


/*
Expand Down Expand Up @@ -63,8 +76,20 @@ Expected Output:
*/

// ✍️ Solve it here ✍️


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)

/*
Task 3: Supercar Feature Adder 🚗 🚗 🚗 🚗
Expand All @@ -86,14 +111,6 @@ Steps:

Example:
Input:
const supercar = {
model: "Ferrari SF90",
price: 500000,
features: {
color: "Red"
}
};

addFeature(supercar, "turbo");

Expected Output:
Expand All @@ -104,3 +121,18 @@ Features:
*/

// ✍️ Solve it here ✍️
const supercar = {
model: "Ferrari SF90",
price: 500000,
features: {
color: "Red"
}
};
function addFeature(supercar, feature){
supercar.features.feature=true;
console.log(`${feature} has been added`);
}
addFeature(supercar, "turbo");
for(let key in supercar.features){
console.log(`${key}: ${supercar.features[key]}`);
}