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
55 changes: 52 additions & 3 deletions arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Expected Output:

// ✍️ Solve it here ✍️

let inventory = [ "Bread","Milk","Eggs",];




inventory.push("Orange","Banana");
console.log(inventory)
/*
Task 2: Student Attendance Checker 📚✅

Expand All @@ -41,6 +41,19 @@ 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"));
console.log(isPresent("Iqra"));



Expand Down Expand Up @@ -68,6 +81,42 @@ Output: Sorted leaderboard with updated scores
// ✍️ Write your functions here ✍️


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

];

function updateScore(name, scoreToAdd) {
let playerFound = false;

for (let i = 0; i < topScorers.length; i++) {
if (topScorers[i].name === name) {
topScorers[i].score += scoreToAdd;
playerFound = true;
break;
}
}

if (!playerFound) {
topScorers.push({ name: name, score: scoreToAdd });
}
}

// didn`t finnish yet

function printLeaderboard() {
topScorers.sort((a, b) => b.score - a.score);

console.log("Top Scorers Leaderboard:");
for (let player of topScorers) {
console.log(`${player.name}: ${player.score}`);
}
}
updateScore("Ronaldo", 2);
printLeaderboard();




Expand Down
44 changes: 44 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 ✍️

// the welcome callback function

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

function sendMessage(userName, callback) {
callback(userName);
}
sendMessage("Amina", theCallBackFunction);



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


// The call back function
function thecallBackFunction(tempreture) {
if (tempreture > 30) {
console.log(`${tempreture}°C is Hot.`);
}else if (tempreture >= 15 && tempreture <= 30) {
console.log(`${tempreture}°C is Warm.`)
}else {
console.log(`${tempreture}`)
}
}

function checkTemperature(value, callback) {
callback(value);
}
checkTemperature(40, thecallBackFunction)








/*
Expand All @@ -73,3 +105,15 @@ Expected Output:
*/

// ✍️ Solve it here ✍️

function TheCallBackFunction(userAnswer, correctAnswer) {
if (userAnswer === correctAnswer) {
console.log("Correct!");
} else {
console.log(`Incorrect. The correct answer is ${correctAnswer}.`);
}
}
function evaluateAnswer(question, correctAnswer, callback) {
const userAnswer = prompt(question);
callback(userAnswer, correctAnswer);
}
3 changes: 2 additions & 1 deletion 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 -->
</body>
<script src="callbacks.js"></script>
</body >
</html>
54 changes: 54 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ 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 ononline.`);
} else {
console.log(`${profile.username} is now offline`);
}
}

updateOnlineStatus(gamerProfile,true);
updateOnlineStatus(gamerProfile, false);







/*
Expand Down Expand Up @@ -64,6 +86,21 @@ Expected Output:

// ✍️ Solve it here ✍️

const dress = {
name: "Evening Gown",
size: "M",
inStock: true
};

// checkAvailability(dress) {
if (dress.inStock) {
console.log(`${dress.name} is available in size ${dress.size}.`);
}else {
console.log(`${dress.name} is out of stock`)
}





/*
Expand Down Expand Up @@ -104,3 +141,20 @@ Features:
*/

// ✍️ Solve it here ✍️


//The superCar object

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

// addFeature Function
function addFeature(Car, featureName) {
Car.feature[featureName] = true;
console.log(`featureName.charAt(0) .toUpperCase() + featureName.slice(1} has been added to $ {car.model})`);
}