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
34 changes: 33 additions & 1 deletion arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ 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 +43,15 @@ 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.`;
}
}



Expand Down Expand Up @@ -67,7 +79,27 @@ 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, addedScore) {
const player=topScorers.find(p=> p.name===playerName);
if (player) {
player.score +=addedScore;
}else {
topScorers.push({name: playerName, score: addedScore});
}
}
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`);
})
}



Expand Down
32 changes: 31 additions & 1 deletion callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ Expected Output:

// ✍️ Solve it here ✍️


function welcomeMessege(name) {
console.log(`welcome, ${name}!`);
}
function sendMessage(userName, callback) {
callback(userName)
}


/*
Expand Down Expand Up @@ -48,7 +53,19 @@ 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(tempValue, callback) {
callback(tempValue)
}


/*
Expand All @@ -73,3 +90,16 @@ Expected Output:
*/

// ✍️ Solve it here ✍️

function checkUseranswer(user answer, correctAnswer) {
if (userAnswer===correctAnswer) {
console.log("correct");
}else {
console.log(`incorect. the correct answer is ${correctAnswer}`);
}

}
function evaluateAnswer(question, correctAnswer, callback) {
const userAnswe=prompt(question);\
callback(userAnswer, correctAnswer)
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<h1>Look at the console to see the results</h1>

<!-- Before starting, add the javascript files in this html fie -->
<script> src="js/script.js"</script>
</body>
</html>
43 changes: 42 additions & 1 deletion objects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
]/*
Task 1: Gamer Profile Manager 🎮 🎮 🎮 🎮

You are creating a system to manage a gamer's profile.
Expand Down Expand Up @@ -30,7 +30,19 @@ Expected Output:

// ✍️ Solve it here ✍️

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

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

/*
Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗
Expand Down Expand Up @@ -64,7 +76,19 @@ 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.`);
}
}

/*
Task 3: Supercar Feature Adder 🚗 🚗 🚗 🚗
Expand Down Expand Up @@ -104,3 +128,20 @@ 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.charArt(0).toUpperCase()+ featureName.slice(1)} has been added to ${car.model}.`);
}
addFeature(supercar, "turbo");
console.log("feutures:");
for (let feature in supercar.features) {
console.log(`- ${feature}: ${supercar.features[feature]}`);
}