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
27 changes: 27 additions & 0 deletions akjlaödsfdsfkaj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=mukhtaarbatuun
user.email=mukhtaarbatuun1@gmail.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://github.com/gabischool/Week5_JS_Assignment.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
branch.main.vscode-merge-base=origin/main
branch.mukhtaarbatuun.vscode-merge-base=origin/main
53 changes: 46 additions & 7 deletions arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Expected Output:

// ✍️ Solve it here ✍️



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


/*
Expand All @@ -40,11 +42,19 @@ Output: "Ali is present."

// ✍️ Write your function here ✍️






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

console.log(isPresent("Ali"));
console.log(isPresent("Ahmed"));
console.log(isPresent("Hassan"));
/*
Task 3: Top Scorers Leaderboard 🏆⚽

Expand All @@ -69,6 +79,35 @@ Output: Sorted leaderboard with updated scores



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

const updateScore = (playerName, goalScore) => {
const player = topScorers.find(scorer => scorer.name === playerName);
if (player) {
player.score += goalScore;
} else {
topScorers.push({ name: playerName, score: goalScore });
}
};
const printLeaderboard = () => {
const sortedLeaderboard = [...topScorers];
sortedLeaderboard.sort((a, b) => b.score - a.score);

console.log("Top Scorers Leaderboard:");
sortedLeaderboard.forEach((scorer, index) => {
console.log(`${index + 1}. ${scorer.name}: ${scorer.score}`);
});
};

printLeaderboard();
updateScore("Ronaldo", 2);
printLeaderboard();





Expand Down
33 changes: 30 additions & 3 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ Expected Output:

// ✍️ Solve it here ✍️




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

sendMessage("Amina" , welcomemessage)
/*
Task 2: Temperature Checker 🌡️🌡️🌡️🌡️

Expand Down Expand Up @@ -48,6 +53,28 @@ Expected Output:

// ✍️ Solve it here ✍️

const evaluateTemperature =(temperature) => {
let status;
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.`)
}


};

const checkTemperature = (temperature, callback) => {
callback(temperature);
};

checkTemperature(35, evaluateTemperature);
checkTemperature(22, evaluateTemperature);
checkTemperature(10, evaluateTemperature);




Expand Down
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<body>
<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="callbacks.js"> </script>
<script src="objects.js"> </script>
</body>
</html>
63 changes: 63 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ Expected Output:




const gamerProfile = {
username: "ShadowSlayer",
level: 5,
isOnline: false
};
const 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 @@ -64,6 +90,23 @@ Expected Output:

// ✍️ Solve it here ✍️

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

const checkAvailability = (dressItem) => {
if (dressItem.inStock) {
console.log(`${dressItem.name} is available in size ${dressItem.size}.`);
} else {
console.log(`${dressItem.name} is out of stock.`);
}
};

checkAvailability(dress)




/*
Expand Down Expand Up @@ -104,3 +147,23 @@ Features:
*/

// ✍️ Solve it here ✍️

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

const addFeature= (car , featureName) => {
car.features[featureName]=true;
console.log(`${featureName} has been added to ${car.model}.`);
};

addFeature(supercar, "turbo");

console.log("Features:");
for (let feature in supercar.features) {
console.log(`- ${feature}: ${supercar.features[feature]}`);
}