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
53 changes: 52 additions & 1 deletion arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Expected Output:

// ✍️ Solve it here ✍️

const inventory =["milk", "apple","chocolate","bread","eggs"]

inventory:push("orange","bananas");

inventory:finish();

console.log("Updated inventory",inventory)



Expand All @@ -39,7 +46,17 @@ Output: "Ali is present."
*/

// ✍️ Write your function here ✍️
const students = ["ahmed","ayaan","nimco","hassan"];
function isPresent(name){
if(students.includes(name)){
return `${name} is present`;
}else{
return `${name} is absent`;

}
}
console.log(students("nimco"));
console.log(student("ahmed"))



Expand All @@ -66,7 +83,41 @@ Output: Sorted leaderboard with updated scores
*/

// ✍️ Write your functions here ✍️


const topScorers = [
{name: "messi", score: 10},
{name:"Ronaldo", score: 8},
{name: "Naymer", score: 6},
]

function updateScore(playerName, points) {
let found = false;

for (let i = 0; i < topScorers.length; i++) {
if (topScorers[i].name === playerName) {
topScorers[i].score += points;
found = true;
break;
}
}
if (!found) {
topScorers.push({ name: playerName, score: points });
}
}
function printLeaderboard(){
topScorers.sort(function(a,b){
return b.score - a.score;
});
}

for (let i = 0; i < topScorers.length; i++){
console.log(topScorers[i].name + ":" + topScorers[i].score);
}

updateScore("Messi", 10)
printLeaderboard();





Expand Down
38 changes: 38 additions & 0 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Expected Output:
// ✍️ Solve it here ✍️


function showWelcome(name) {
console.log("Welcome, " + name + "!");
}
function sendMessage(userName, callbackFn) {
callbackFn(userName);
}
sendMessage("Ahmed", showWelcome);



/*
Expand Down Expand Up @@ -47,6 +55,23 @@ Expected Output:
*/

// ✍️ Solve it here ✍️

function readTemperature(value) {
if (value > 30) {
console.log(value + "°C is Hot.");
} else if (value >= 15 && value <= 30) {
console.log(value + "°C is Warm.");
} else {
console.log(value + "°C is Cold.");
}
}
function checkTemperature(temp, callbackFn) {
callbackFn(temp);
}

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



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

// ✍️ Solve it here ✍️
function checkUserAnswer(userAnswer, rightAnswer) {
if (userAnswer === rightAnswer) {
console.log("Correct!");
} else {
console.log("Incorrect. The correct answer is " + rightAnswer + ".");
}
}

function checkUserAnswer(){
let userInput = prompt(question);
callbackFn(userInput, correctAnswer);
}

4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
<h1>Look at the console to see the results</h1>

<!-- Before starting, add the javascript files in this html fie -->

<script src="js/arrays.js"></script>
<script src="js/callbacks.js"></script>
<script src="js/objects.js"></script>
</body>
</html>
47 changes: 46 additions & 1 deletion objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,22 @@ Expected Output:
*/

// ✍️ Solve it here ✍️


const gamerProfile = {
username: "nightHunter",
level: 12,
isOnline: false
}
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.");
}
}
updateonlineStatus(gamerProfile,true);


/*
Expand Down Expand Up @@ -64,7 +79,20 @@ Expected Output:

// ✍️ Solve it here ✍️

const dress = {
name: "Summer Dress",
size: "L",
inStock: false
};

function checkAvailability(dressItem) {
if (dressItem.inStock === true) {
console.log(dressItem.name + " is available in size " + dressItem.size + ".");
} else {
console.log(dressItem.name + " is out of stock.");
}
}
checkAvailability(dress);

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

// ✍️ Solve it here ✍️

const supercar = {
model: "Lambo V12",
price: 450000,
features: {
color: "Black"
}
};
function addFeature(car, featureName) {
car.features[featureName] = true;
console.log(featureName + " has been added to " + car.model + ".");
}
addFeature(supercar, "spoiler");
console.log("Features:");
for (let item in supercar.features) {
console.log("- " + item + ": " + supercar.features[item]);
}