Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submitted week 5 #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
68 changes: 67 additions & 1 deletion arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ Expected Output:
- Updated inventory
*/

// ✍️ Solve it here ✍️
// ✍️ Solve it here

const inventory = ["Apples", "Bread", "Milk", "Eggs"];
//index 0 1 2 3
console.log (inventory);

inventory.splice(0)

console.log(inventory);


inventory.unshift("oranges");

console.log(inventory);


inventory.unshift("bananas")
console.log(inventory);


/*
Expand All @@ -40,9 +54,26 @@ Output: "Ali is present."

// ✍️ Write your function here ✍️

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


function isPresent (students,isPresent)
{


if (isPresent==true)


{console.log ( ` ${students} is present.`)}

else if (isPresent=false) {console.log (`${students}is absent.`)}




}

isPresent("ali",true)


/*
Expand All @@ -66,6 +97,41 @@ 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 = topScorers.find(player => player.name === playerName);

if (player) {

player.score += scoreToAdd;
} else {

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


function printLeaderboard() {

topScorers.sort((a, b) => b.score - a.score);

topScorers.forEach(player => {
console.log(`${player.name}: ${player.score}`);
});
}

updateScore("ronaldo",10)

printLeaderboard();






Expand Down
45 changes: 44 additions & 1 deletion callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ Expected Output:

// ✍️ Solve it here ✍️

function sendMessageHOF(name, callback){

return callback(name)
}

function sendMessageCB(name)

{ console.log (`welcome ${name}`)





}

sendMessageHOF("abdi",sendMessageCB)
/*
Task 2: Temperature Checker 🌡️🌡️🌡️🌡️

Expand Down Expand Up @@ -48,8 +61,38 @@ Expected Output:

// ✍️ Solve it here ✍️

function checkTemperatureHOF (temperature,callback){

return callback(temperature)

}

function checkTemperatureCB(temperature){

if (temperature > 10 && temperature <22)

console.log (`${temperature} is Warm`)


else if (temperature < 10)

{

console.log (`${temperature} is Cold` )

}

else {
console.log (`${temperature} is Hot`)



}
}

checkTemperatureHOF (100,checkTemperatureCB)

let temperature = prompt("please enter the temp")

/*
STRETCH: Task 3: Quiz Evaluator 📚📚📚📚
Expand All @@ -71,5 +114,5 @@ Expected Output:
- If user's input is "10": "Correct!"
- If user's input is "15": "Incorrect. The correct answer is 10."
*/

// ✍️ Solve it here ✍️
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<body>
<h1>Look at the console to see the results</h1>

<!-- Before starting, add the javascript files in this html fie -->
<script type="text/javascript" src="arrays.js"></script>
<script type="text/javascript" src="objects.js"></script>
<script type="text/javascript" src="callbacks.js "></script>




</body>
</html>
76 changes: 75 additions & 1 deletion objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,40 @@ const gamerProfile = {
isOnline: false
};

updateOnlineStatus(gamerProfile, true);


Expected Output:
"ShadowSlayer is now online."
*/

// ✍️ Solve it here ✍️

const gamerProfile = {
username: "ShadowSlayer",
level: 5,
isOnline: false
};


updateOnlineStatus(gamerProfile, true);





function updateOnlineStatus(gamerProfile, status) {

gamerProfile.isOnline = "status";


if ("status") {
console.log(`${gamerProfile.username} is now online.`);
} else {
console.log(`${gamerProfile.username} is now offline.`);
}
}

updateOnlineStatus(gamerProfile, "status");


/*
Expand Down Expand Up @@ -64,6 +90,23 @@ Expected Output:

// ✍️ Solve it here ✍️

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

function checkAvailability(dress) {
if (dress.inStock) {
console.log(`${dress.name} is available in size ${dress.size}.`);
} else {
console.log(`${dress.name} is out of stock.`);
}
}

checkAvailability(dress)




/*
Expand Down Expand Up @@ -104,3 +147,34 @@ 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}.`);
}


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


addFeature(supercar, "turbo");
logFeatures(supercar);