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
Binary file added .DS_Store
Binary file not shown.
32 changes: 25 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,9 +42,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`
}
}
console.log(isPresent("Ali"))


/*
Expand All @@ -67,10 +75,20 @@ 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) {
for (let i = 0; i < topScorers.length; i++)
if ( topScorers [i].name === playerName && topScorers[i].score === scoreTOAdd) {
return updateScore
} else topScorers.push({name: playerName, score: scoreTOAdd})
}



console.log(topScorers)


/*
Expand Down
27 changes: 25 additions & 2 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ Expected Output:

// ✍️ Solve it here ✍️


function sendMessage(userName, cb) {
return cb (userName)
}
function theCallBackFunction(userName){
console.log(`Welcome ${userName}`)
}
sendMessage("Amina", theCallBackFunction)


/*
Task 2: Temperature Checker 🌡️🌡️🌡️🌡️


You are creating a temperature monitoring system. Write a function called `checkTemperature` that:
1. Takes a temperature value and a callback function as arguments.
2. The callback function should evaluate whether the temperature is "Hot", "Warm", or "Cold" based on the following:
Expand All @@ -48,6 +53,24 @@ Expected Output:

// ✍️ Solve it here ✍️

function checkTemperature(tempretureValue, cb){
return cb(tempretureValue)
}

function theCallBackFunction(tempretureValue){
if(tempretureValue >= 30){
console.log(`${tempretureValue}°C is hot`)
} else if(tempretureValue >= 15 && tempretureValue <= 30) {
console.log(`${tempretureValue}°C is Warm`)
} else if(tempretureValue <= 15) {
console.log(`${tempretureValue}°C is cold`)
} else {
console.log("put the tempreture value here")
}

}

checkTemperature(10, theCallBackFunction)



Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<head>Week 5 Assignment</head>
<body>
<h1>Look at the console to see the results</h1>
<script src="arrays.js"></script>
<script src="callbacks.js"></script>
<script src="objects.js"></script>

<!-- Before starting, add the javascript files in this html fie -->
</body>
Expand Down
47 changes: 47 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ Expected Output:

// ✍️ Solve it here ✍️

const gamerProfile = {
username: "ShadowSlayer",
level: 5,
isOnline: false,
updateOnlineStatus: function(gamerStatus){
if(gamerStatus === true)
return `${this.username} is now online.`
else{
return `${this.username} is now absent`
}
}
};
console.log(gamerProfile.updateOnlineStatus(true))


/*
Expand Down Expand Up @@ -64,6 +77,20 @@ Expected Output:

// ✍️ Solve it here ✍️

const dress = {
name: "Evening Gown",
size: "M",
inStock: true,
checkAvailability: function(dressAvailability){
if(dressAvailability === true)
return`${this.name} is available in size ${this.size}`
else{
return `${this.name} is not available in size ${this.size}`
}
}
}
console.log(dress.checkAvailability(true))



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

// ✍️ Solve it here ✍️

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

function addFeature(supercar,featureName){
supercar.features[featureName] = true
console.log(`${featureName} has been added to ${supercar.model}`)
}

for (let key in supercar.features){
console.log(`${key}: ${supercar.features[key]}`)
}

addFeature(supercar, "turbo")