Table of contents
- ๐ Chapter 1: Assigning Crewmates (push())
- ๐ Chapter 2: A Crewmate is Eliminated (pop())
- ๐ Chapter 3: New Captain Takes Charge (unshift())
- ๐ Chapter 4: A Crewmate is Lost (shift())
- ๐ Chapter 5: Scanning for Impostors (map())
- ๐ Chapter 6: Searching for Safe Crewmates (filter())
- ๐ Chapter 7: Counting Completed Tasks (reduce())
- ๐ Chapter 8: Finding the Impostor (find())
- ๐ Chapter 9: Finding the Last Task (indexOf())
- ๐ Chapter 10: Restoring the System (slice())
- ๐ The Final Vote
It was a normal day on the Skeld, the spaceship traveling through space. 10 crewmates were working hard, fixing wires, downloading data, and refueling engines.
But there was a problemโฆ Two impostors were among them! They had hacked the shipโs security system and were deleting important files. The crewmates had to restore the system using JavaScript arrays before it was too late!
๐ Chapter 1: Assigning Crewmates (push()
)
The game started. The computer randomly added players to the crew.
let crewmates = ["Red", "Blue", "Green"];
crewmates.push("Yellow");
console.log(crewmates);
// Output: ["Red", "Blue", "Green", "Yellow"]
โ Yellow joins the spaceship!
๐ Chapter 2: A Crewmate is Eliminated (pop()
)
An emergency meeting! Red was found dead in Electrical.
let eliminated = crewmates.pop();
console.log(crewmates);
// Output: ["Red", "Blue", "Green"]
console.log(eliminated);
// Output: "Yellow"
โ Yellow is ejected! But was he the impostor?
๐ Chapter 3: New Captain Takes Charge (unshift()
)
"Someone needs to lead us!" said Blue.
crewmates.unshift("Blue");
console.log(crewmates);
// Output: ["Blue", "Red", "Green"]
โ Blue takes charge of the mission.
๐ Chapter 4: A Crewmate is Lost (shift()
)
While fixing wires, Green disappeared!
let missingCrewmate = crewmates.shift();
console.log(crewmates);
// Output: ["Red", "Green"]
console.log(missingCrewmate);
// Output: "Blue"
โ Was Green the impostor? Or is something more sinister happening?
๐ Chapter 5: Scanning for Impostors (map()
)
The remaining crewmates decided to check if anyone was acting suspicious.
let scannedCrewmates = crewmates.map(player => player + " (Scanned)");
console.log(scannedCrewmates);
// Output: ["Red (Scanned)", "Green (Scanned)"]
โ No impostors detectedโฆ yet!
๐ Chapter 6: Searching for Safe Crewmates (filter()
)
"We need to separate real crewmates from impostors!" said Blue.
let allPlayers = ["Red", "Blue", "Impostor1", "Impostor2"];
let realCrewmates = allPlayers.filter(player => !player.includes("Impostor"));
console.log(realCrewmates);
// Output: ["Red", "Blue"]
โ The impostors are still hiding!
๐ Chapter 7: Counting Completed Tasks (reduce()
)
The crew checked how many tasks were left to complete before winning.
let tasksDone = [2, 3, 5, 4];
let totalTasks = tasksDone.reduce((total, task) => total + task, 0);
console.log(totalTasks);
// Output: 14
โ Only a few tasks left! Can they finish before the impostors strike?
๐ Chapter 8: Finding the Impostor (find()
)
Cameras caught someone venting! The crew checked the logs.
let players = [
{ name: "Red", role: "Crewmate" },
{ name: "Blue", role: "Crewmate" },
{ name: "Yellow", role: "Impostor" }
];
let impostor = players.find(player => player.role === "Impostor");
console.log(impostor);
// Output: { name: "Yellow", role: "Impostor" }
โ Yellow is the impostor! Time to vote!
๐ Chapter 9: Finding the Last Task (indexOf()
)
The crewmates had one last task to finish before winning!
let tasks = ["Fix Wires", "Upload Data", "Start Reactor"];
let lastTask = tasks.indexOf("Start Reactor");
console.log(lastTask);
// Output: 2
โ Run to Reactor Room before the impostor sabotages!
๐ Chapter 10: Restoring the System (slice()
)
The crewmates finally recovered the lost security files.
let systemData = ["Start", "Load", "Restore", "Execute"];
let finalSteps = systemData.slice(1, 3);
console.log(finalSteps);
// Output: ["Load", "Restore"]
โ The system is fixed! Time to eject the impostor.
๐ The Final Vote
An emergency meeting was called.
"Yellow is the impostor!"
Everyone voted. Yellow was ejected.
console.log("Impostor was ejected. Crew wins!");
๐ Crewmates Win! The ship is saved! ๐