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

// ✍️ Solve it here ✍️
let inventory = ["Apples", "Bread", "Milk", "Eggs"];
console.log(inventory);
inventory.push("orange", "banana")
console.log(inventory)

inventory.shift()
console.log(inventory)

// i done



Expand All @@ -40,17 +47,22 @@ Output: "Ali is present."

// ✍️ Write your function here ✍️




const student = ["Ali", "Fatima", "Hassan", "Layla"];
function isPresent (studentsName){
if(student.includes(studentsName)){
return `${studentsName} is present`
} else return `${studentsName} is absent`
}
console.log(isPresent("Hassan"));


/*
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.
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:
Expand All @@ -67,7 +79,16 @@ Output: Sorted leaderboard with updated scores

// ✍️ Write your functions here ✍️


const topScorers = [
{name: "Abdi", score: 8},
{name: "Duraan", score:10},
{name:"Ahmed", score:6}
];
function printLeaderboard (){
return `${topScorers} Sorted leaderboard with updated scores`;
}
console.log(printLeaderboard("Abdi", 2));
// this i confuse



Expand Down Expand Up @@ -138,4 +159,4 @@ Final Output:
- "The treasure remains hidden. Try again!" (if danger is encountered)
- "Congratulations! You found the ultimate treasure!" (if all conditions are met)

*/
*/
25 changes: 23 additions & 2 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ Expected Output:
- "Welcome, Amina!"
*/

// ✍️ Solve it here ✍️

// ✍️ Solve it here ✍️f

function sendMessage (callback, userName){
return callback(userName)
}
function message (userName){
console.log(` wellcome ${userName} `)
}
sendMessage(message, "Amina")


/*
Expand Down Expand Up @@ -48,6 +54,21 @@ Expected Output:

// ✍️ Solve it here ✍️

function checkTemperature (tep, callback){
return callback(tep)
}
function evaluate (tep){
if(tep==30){
console.log(`the temperature is Hot`)
} else if (tep===22){
console.log(`the temperature is warm`)
} else if (tep===10){
console.log(`the temperature is cold`)
} else {
console.log(`please select 30-10`)
}
}
checkTemperature(30, evaluate);



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>
63 changes: 61 additions & 2 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ Expected Output:

// ✍️ Solve it here ✍️

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

// 2. Function to update online status
function updateOnlineStatus(profile, status) {
profile.isOnline = status;

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

// Example call:
updateOnlineStatus(gamerProfile, true);








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

// ✍️ Solve it here ✍️


const dress = {
name: "Evening Gown",
size: "M",
inStock: true
};
function checkAvailability(dress){
if(checkAvailability===dress){
console.log(`${dress} is available in size ${size}, `)
} else {
console.log(`${dress} is not available`)
}

}
console.log(checkAvailability(dress.name))

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

// ✍️ Solve it here ✍️


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

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

addFeature(supercar, "turbo");

console.log("Features:");
for (let key in supercar.features) {
console.log("- " + key + ": " + supercar.features[key]);
}


// i tried unfortunitly i confuse i couldn't solve