Table of contents
- Story Build Up :
- length → counting students for picnic :
- forEach → submitting student list to principal :
- pop → Shreyash cancels the trip and is removed from the list :
- push → Chahal takes Shreyash’s place and joins the trip :
- Bus Arrangement :
- entries → allocating seats to students in the bus :
- splice → solving seating problem between Tilak and Chahal :
- filter & include → selecting players for tug of war game :
- Concat → Hitesh Sir’s story Time for all :
Story Build Up :
Note: In this story, the bus has single-row seats, and the driver’s and teacher’s seats are not included. The total number of seats in the bus is 7.
Chai Code School wants to take its students on a picnic. For this, the principal issues a notice so that interested students can register their names for the picnic. Many students submit their names to their teacher.
length → counting students for picnic :
There are a total of 7 boys and 7 girls, which makes 7+7=14 in total.
let stdBoys=["Virat","Rohit","Hardik","Surya","Jassi","Tilak","shreyash"];
let stdGirls=["Smriti","Jamimah","Harleen","Harmanpreet","Renuka","Deepti","Richa"];
console.log(`Total Number Of Student `+(stdBoys.length+stdGirls.length));
//Output :-
// Output :- Total Number Of Student 14
forEach → submitting student list to principal :
Hitesh Sir submits the list of students to the principal.
let stdBoys=["Virat","Rohit","Hardik","Surya","Jassi","Tilak","shreyash"];
let stdGirls=["Smriti","Jamimah","Harleen","Harmanpreet","Renuka","Deepti","Richa"];
stdBoys.forEach((stud)=>
{
console.log(stud);
});
/*
Output:-
Virat
Rohit
Hardik
Surya
Jassi
Tilak
shreyash
*/
Similarly you can see the list of girls also.
Boys List :-
Girls List:-
pop → Shreyash cancels the trip and is removed from the list :
A day before the picnic, one of the boys, Shreyash, falls sick and cancels his trip. So, his name is removed from the list.
let stdBoys=["Virat","Rohit","Hardik","Surya"," Jassi"," Tilak ","shreyash"];
let removestud = stdBoys.pop();
console.log(stdBoys);
console.log(removestud);
/*
Output :-
[ 'Virat', 'Rohit', 'Hardik', 'Surya', 'Tilak', 'Jassi' ]
Shreyash
*/
After Pop Method
push → Chahal takes Shreyash’s place and joins the trip :
When Chahal finds out that Shreyash has canceled his trip, he decides to go in his place. He submits his name to Hitesh Sir, and his name is added to the group list.
let stdBoys=["Virat","Rohit","Hardik","Surya"," Jassi"," Tilak ","shreyash"];
//let removestud = stdBoys.pop();
//console.log(removestud);
let newStud =stdBoys.push("Chahal");
console.log(stdBoys);
console.log(newStud);
/*
Output:-
[ 'Virat', 'Rohit', 'Hardik', 'Surya', 'Tilak', 'Jassi' ]
['Virat', 'Rohit','Hardik', 'Surya','Tilak', 'Jassi','Chahal']
*/
After Apply Push Method
Bus Arrangement :
Since each bus has 7 seats, two buses are needed for the students. The students are divided into two groups: boys in one bus and girls in another. Hitesh Sir accompanies the boys, while Piyush Sir goes with the girls.
Now, let's focus on the boys' bus because Piyush Sir will easily manage the girls, as he is their favorite (+1).
entries → allocating seats to students in the bus :
All students are assigned seats in the bus along with seat numbers.
let stdBoys=["Virat","Rohit","Hardik","Surya"," Jassi"," Tilak ","shreyash"];
let removestud = stdBoys.pop();
let newStud =stdBoys.push("Chahal");
let SeatAllotment = stdBoys.entries();
for(let[index,value]of SeatAllotment)
{
console.log(index,value);
}
/*
Output:-
0 Virat
1 Rohit
2 Hardik
3 Surya
4 Tilak
5 Jassi
6 Chahal
*/
After Seat Allocate
Similarly, girls were also given seats in the bus.
splice → solving seating problem between Tilak and Chahal :
The driver starts the bus, and it speeds down the road.
But in the boys’ bus, Chahal starts teasing Tilak, which leads Tilak to complain to Hitesh Sir. To solve the problem, Hitesh Sir makes Jassi sit between Tilak and Chahal.
let stdBoys=["Virat","Rohit","Hardik","Surya","Jassi"," Tilak ","shreyash"];
//let removestud = stdBoys.pop();
//let newStud =stdBoys.push("Chahal");
function BadmasStud(arr,fromSeat,toSeat)
{
let element = arr[fromSeat];
arr.splice(fromSeat,1);
arr.splice(toSeat,0,element);
}
BadmasStud (stdBoys,4,5);
console.log(stdBoys);
/*
Output:-
['Virat', 'Rohit','Hardik', 'Surya','Tilak', 'Jassi', 'Chahal']
*/
After Badmosi seating Arrange
filter & include → selecting players for tug of war game :
The bus finally reaches the picnic spot. Some teachers start cooking food, while Hitesh Sir and Piyush Sir organize a tug-of-war game. Hitesh Sir selects 4 boys, and Piyush Sir selects 4 girls for the game.
let stdBoys=["Virat","Rohit","Hardik","Surya","Jassi","Tilak","shreyash"];
let stdGirls=["Smriti","Jamimah","Harleen","Harmanpreet","Renuka","Deepti","Richa"];
let SelectedBoy =["Virat","Hardik","Surya","Jassi"];
let teamBoy =stdBoys.filter(stdBoys=>SelectedBoy.includes(stdBoys));
console.log(teamBoy);
/*
Output :-
[ 'Virat', 'Hardik', 'Surya', 'Jassi' ]
*/
Similarly, a team of girls is also formed.
Concat → Hitesh Sir’s story Time for all :
After the game, everyone eats together. Later, Hitesh Sir gathers all the students and tells them a wonderful story, just like always.
let stdBoys=["Virat","Rohit","Hardik","Surya","Jassi"," Tilak ","shreyash"];
let stdGirls=["Smriti","Jamimah","Harleen","Harmanpreet","Renuka","Deepti","Richa"];
//let removestud = stdBoys.pop();
//let newStud =stdBoys.push("Chahal");
let Group=stdBoys.concat(stdGirls);
console.log(Group);
/*
Output :-
['Virat', 'Rohit', 'Hardik', 'Surya', 'Tilak', 'Jassi',
'Chahal', 'Smriti', 'Jamimah', 'Harleen', 'Harmanpreet',
'Renuka', 'Deepti', 'Richa']
*/
Hitesh sir telling story to students
By 5 PM, it's time to leave. All students board the buses, and they head back home.
THANK YOU!
Now, you must be wondering who won the tug-of-war?
Well, if you give me a hoodie, I'll tell you!