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
51 changes: 51 additions & 0 deletions arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ Expected Output:

// ✍️ Solve it here ✍️

const inventory = ["Apples", "Bread", "Milk", "Eggs"];


inventory.push("Orange","Bannanes", );


inventory.shift();
console.log("Uppdated inventory:", inventory);

/*
Task 2: Student Attendance Checker 📚✅
Expand All @@ -40,6 +45,20 @@ Output: "Ali is present."

// ✍️ Write your function here ✍️

const students = ["Ali", "Fatima", "Hassan", "Layla"];

function isPresent(name) {
if(students.includes(name)){
return `${name} ispresent.`;
else{
return `${name} is absent.`;

}
}
}
console.log(isPresent("ali"));





Expand Down Expand Up @@ -68,6 +87,34 @@ 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, ScoreToadd){
const player= score.find(p => p.name ===playerName);
if(player) {
player.score += ScoreToadd;
else{
topScorers.push({name:playerName, score.ScoreToadd});

}

}

}

function printLeaderboard() {
const Sorted =[...topScorers]. sort ((a,b )=> b.score - a.score);
console.log("leader board:");
Sorted.forEach((player, index) => {
console.log(`${index +1}.${player.name} -${player.score}`);

});

}



Expand Down Expand Up @@ -139,3 +186,7 @@ Final Output:
- "Congratulations! You found the ultimate treasure!" (if all conditions are met)

*/

function findClue(clues, Map){

}
52 changes: 52 additions & 0 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Expected Output:
*/

// ✍️ Solve it here ✍️
function welcomeMessage(_name){
console.log(`wellcome{name}!`);
}
function sendMessage(username, callback){
callback(username);

}


sendMessage("Amina", welcomeMessage);



Expand Down Expand Up @@ -49,7 +59,30 @@ Expected Output:
// ✍️ Solve it here ✍️


function checkTemperatur(temperature){
if(temperature > 30){
console.log(`$ {temp} cº is hot.`);
}else if(temperature >= 15 && temperature <= 30){
console.log(`$ {temp} cº is warm.`);
}else{
console.log(`${temperature} cº is cold.`);

}

}
function checkTemperatur(temperature, callback){
callback(temperature);

}



checkTemperature(35, checkTemperature);

checkTemperature(22,checkTemperature);


checkTemperature(10, checkTemperature);

/*
STRETCH: Task 3: Quiz Evaluator 📚📚📚📚
Expand All @@ -73,3 +106,22 @@ Expected Output:
*/

// ✍️ Solve it here ✍️

function evaluateAnswer(userAnswer, _correct){
if(userAnswer === correctAnswer){
console.log("correct1");
else{
console.log (`incorrect. the correct answer is ${correctAnswer}.`);

}
}
}
function evaluateAnswer(question, correctAnswer, callback){
const userAnswer = prompt(question);
callback(userAnswer, correctAnswer);
}




evaluateAnswer("What is 5 + 5?", "10", TheCallBackFunction);
46 changes: 46 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,24 @@ 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 online.`);

}else{
console.log(`${profile.username} is now offline.`);

}

}
updateOnlineStatus(gamerProfile, true);

/*
Task 2: Dress Inventory Checker 👗 👗 👗 👗 👗
Expand Down Expand Up @@ -63,8 +80,23 @@ Expected Output:
*/

// ✍️ Solve it here ✍️
const dress = {
name: "Evening Gown",
size: "M",
inStock: true
};

function checkAvailabilit(dress){
if (dress.instock){
console.log(`${dress.name} is avilabe in size ${dress.size}.`);

}else {
console.log(`${dress.name}is out of stock.`);

}

}
checkAvailabilit(dress);

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

// ✍️ Solve it here ✍️
const supercar = {
model: "ferrari SF90 ",
price: 500000,
features:{
color: "Red"

}

};
function addFeature(car, featureName){
car.features[featureName]= true;


}