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
33 changes: 33 additions & 0 deletions arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Expected Output:
*/

// ✍️ Solve it here ✍️
inventory.push("Oranges", "Bananas");
inventory.shift();
console.log(inventory);



Expand All @@ -39,6 +42,14 @@ Output: "Ali is present."
*/

// ✍️ Write your function here ✍️
function isPresent(name) {
if (students.includes(name)) {
return `${name} is present.`;
} else {
return `${name} is absent.`;
}
}




Expand Down Expand Up @@ -66,6 +77,28 @@ Output: Sorted leaderboard with updated scores
*/

// ✍️ Write your functions here ✍️
function updateScore(playerName, scoreToAdd) {

const player = topScorers.find(p => p.name === playerName);

if (player) {

player.score += scoreToAdd;
} else {

topScorers.push({ name: playerName, score: scoreToAdd });
}
}

function printLeaderboard() {

const sorte = topScorers.sort((b, t) => b.score - t.score);

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



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

// ✍️ Solve it here ✍️
function theCallBackFunction(name) {
console.log(`Welcome, ${name}!`);
}


function sendMessage(userName, callback) {

callback(userName);
}



Expand Down Expand Up @@ -47,6 +56,21 @@ Expected Output:
*/

// ✍️ Solve it here ✍️
function evaluateTemperature(temp) {
if (temp > 30) {
console.log(`${temp}°C is Hot.`);
} else if (temp >= 15 && temp <= 30) {
console.log(`${temp}°C is Warm.`);
} else {
console.log(`${temp}°C is Cold.`);
}
}


function checkTemperature(temperature, callback) {

callback(temperature);
}



Expand All @@ -73,3 +97,18 @@ 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);
}

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="arrays.js"></script>
<script src="callbacks.js"></script>
<script src="objects.js"></script>

</body>
</html>
52 changes: 52 additions & 0 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ Expected Output:
*/

// ✍️ Solve it here ✍️
var gamerProfile = {
username: "ShadowSlayer",
level: 5,
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.");
}
}



Expand Down Expand Up @@ -63,6 +79,20 @@ Expected Output:
*/

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


function checkAvailability() {
if (dress.inStock == true) {
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 +134,25 @@ Features:
*/

// ✍️ Solve it here ✍️
var supercar = {
model: "Ferrari SF90",
price: 500000,
features: {
color: "Red"
}
};


function addFeature(car, featureName) {
car.features[featureName] = true;
console.log(featureName + " has been added to " + car.model + ".");
}


addFeature(supercar, "turbo");


console.log("Features:");
for (var feature in supercar.features) {
console.log("- " + feature + ": " + supercar.features[feature]);
}