LWC Bootcamp Day 6 | Looping and Collections in JS

preview_player
Показать описание

This Video Covers

1) Loops in JS
2) Map Collection
3) Set Collection



#js #javascript #loops #collections #map #salesforce #lightning #development #lwc #jsoverview #lighting #salesforcelighting #salesforcetraining #lwcbasics #lwcadvanced #salesforcedeveloper #developer #ankitjain #techjourneywithankit #studysalesforce #lwc #aura #lightningwebcomponent #ankitjain #lwcbootcamp #arrowfunction #callbackfunction
Рекомендации по теме
Комментарии
Автор

𝐀𝐬𝐬𝐢𝐠𝐧𝐦𝐞𝐧𝐭

/*
We're building a Cricket app !

Suppose we get data from a web service about a certain game (below).
In this challenge we're gonna work with the data. So here are your tasks:

1. Create one player array for each team (variables 'players1' and 'players2')
2. The first player in any player array is the wicketkeeper and the others are field players.
For India (team 1) create one variable ('Ind') with the wicketkeeper name,
and one array ('fieldPlayers') with all the remaining 10 field players
3. Create an array 'allPlayers' containing all players of both teams (22 players)
4. During the game, India (team 1) used 3 substitute players. So create a new array ('players1Final')
containing all the original team1 players plus 'Sandeep', 'John' and 'Sunil'
5. Based on the game.odds object, create one variable for each odd (called 'team1', 'draw' and 'team2')
6. The team with the lower odd is more likely to win.
Print to the console which team is more likely to win,
WITHOUT using an if/else statement or the ternary operator.
7. Loop over the game.Century array and print each player name to the
console, along with the Century number (Example: "Century 1: Kohli")
8. Use a loop to calculate the average odd and log it to the console

GOOD LUCK 😀
*/
const game = {
team1: "India",
team2: "Australia",
players: [
[
"Dhoni",
"Sharma",
"Kohli",
"Rahul",
"Jadeja",
"Pandey",
"Ashwin",
"Chahal",
"Khan",
"Bhumra",
"Shami",
],
[
"Wade",
"Cummins",
"Green",
"Maxwell",
"Finch",
"Hazelwood",
"Marsh",
"Stoinis",
"Richardson",
"Starc",
"Warner",
],
],
Century: ["Kohli", "Sharma", "Warner", "Maxwell"],
odds: {
team1: 1.33,
x: 3.25,
team2: 6.5,
},
};

TechJourneyWithAnkit
Автор

Hi Ankit, can't thank how good this session was. Excellent teaching and examples that a newbie on JS can learn. 🙏

sagarr
Автор

Absolutely fantastic session – insightful, engaging and very useful to upskill JavaScript. Thank you so much Ankit...

BaluMahendra
Автор

Thank you sir for Excellent Session & Very Useful Assignment.

saidareddych
Автор

thankyou very much sir for giving awesome content 👏👏👏

gauravjoshi
Автор

can we use for -in loop for map ankit? can u please clarify on it

saimanimekala
Автор

how to print the values of the same opening hours object if there is one more nested objects

DSA_Javascript
Автор

Thanks for this Amazing content Ankit. Can we use for in loop for collections?

Krishnareddy-il
Автор

Hi Ankit,
Thanks for your wonderful and awesome training videos.
I have used for in on object with below code and able to access the property name
for (let currItem in myDetails){
console.log("currItem", currItem);
}
If i ues for of getting error -//myDetails (object) is not iterable
for (let currItem of myDetails){
console.log("currItem", currItem);
}
Iam doing anything wrong here?

kittu
Автор

line number 71 why it didn't work is last time you use object.keys so it was picking keys/index

SalesforceFacts
Автор

When i am using let, var in a loop like


for(let i=0;i<myCar.length;i++){

}

its showing error some reserve keyword like that

ankitpal-uxxn
Автор

//Task 1
let {team1, team2, players: [players1, players2], Century, odds} = game;
console.log(team1);
console.log(team2);
console.log(players1);
console.log(players2);
console.log(Century);
console.log(odds);

/*
Task 2 :The first player in any player array is the wicketkeeper and the others are field players.
For India (team 1)
Create one variable ('Ind') with the wicketkeeper name,
and one array ('fieldPlayers') with all the remaining 10 field players
*/

let [ind, ...fieldPlayers] = players1;
console.log(ind);
console.log(fieldPlayers);

/*
Task 3 :Create an array 'allPlayers' containing all players of both teams (22 players)
*/
let allPlayers = [...players1, ...players2];
console.log(allPlayers);


/*
Task 4. During the game, India (team 1) used 3 substitute players.
So create a new array ('players1Final')
containing all the original team1 players plus 'Sandeep', 'John' and 'Sunil'
*/

let players1Final = [...players1, 'Sandeep', 'John', 'Sunil'];
console.log(players1Final);

/*
Task 5. Based on the game.odds object, create one variable for each odd (called 'team1', 'draw' and 'team2')
*/
let { team1: team1Odd, x: drawOdd, team2: team2Odd } = odds;
console.log(team1Odd);
console.log(drawOdd);
console.log(team2Odd);

/*
Task6. The team with the lower odd is more likely to win.
Print to the console which team is more likely to win,
*/
if (team1Odd < team2Odd) {
console.log(`${team1} is more likely to win.`);
} else {
console.log(`${team2} is more likely to win.`);
}

/*
WITHOUT using an if/else statement or the ternary operator.
*/
console.log(team1Odd < team2Odd ? `${team1} is more likely to win.` : `${team2} is more likely to win.`);

/*
Task 7. Loop over the game.Century array and print each player name to the
console, along with the Century number (Example: "Century 1: Kohli")
*/
for (const [key, value] of Century.entries()) {
console.log(`Century ${key +1} : ${value}`);
}

/*
Task 8. Use a loop to calculate the average odd and log it to the console
*/
let total = 0;
let count = 0;

for (let odd of Object.values(odds)) {
total += odd;
count++;
}
let averageOdd = total / count;
console.log(`Average odd: ${averageOdd}`);

HardCoreDeveloper
visit shbcf.ru