---
# System prepended metadata

title: Story of the Life of the Avengers in the Endgame

---

# Story of the Life of the Avengers in the Endgame
```:javascript=
let allies = ["The Avengers"]
let joiningAllies= [
    "Captain Marvel", 
    "Doctor Strange", 
    "Guardians of the Galaxy", 
    "Black Panther", 
    "Asgard"
];

let year = 2023;

let infinityStones = {
    mind: {name: "Mind", isRetrieved: false},
    power: {name: "Power", isRetrieved: false},
    reality: {name: "Reality", isRetrieved: false},
    soul: {name: "Soul", isRetrieved: false},
    space: {name: "Space", isRetrieved: false},
    time: {name: "Time", isRetrieved: false}
}

let enemy = "Thanos";

let mission = {
    statement: "Retrieve Infinity Stones and reverse the damage caused by Thanos in Infinity War!",
    result: {
        enemyDefeated: false,
        worldPopulationRestored: false
    }
}

function timeTravel(toYear) {
    console.log("Travelling to the year " + toYear + "...");
    year = toYear;
}

function retrieveStone(members, stone, year) {
    timeTravel(year);
    console.log(members + " successfully retrieved " + infinityStones[stone].name + " Stone!");
    infinityStones[stone].isRetrieved = true;
}

function checkStoneStatus() {
    for (let stone in infinityStones) {
        if (infinityStones[stone].isRetrieved == false) {
          console.log("Battle can not start, " + infinityStones[stone].name + " Stone has not been retrieved yet!");
          break;
        }
    }
}

function joinBattle(who) {
    console.log(who + " joining the battle!");
    allies.push(who);
}

function battle() {
    console.log("Starting the battle!");
    for (let i=0; i<joiningAllies.length; i++) {
        joinBattle(joiningAllies[i]);
    }
}

function endOfBattle(allies, enemy) {
    console.log(allies + " defeated " + enemy);
    mission.result.enemyDefeated = true;
    mission.result.worldPopulationRestored = true;
}

// Five years after the Infinity War, 
// The Avengers is going on a new mission...
console.log(mission.statement);
retrieveStone("Guardians of the Galaxy", "power", 2014);
retrieveStone("Iron Man, Captain America and Ant-Man", "space", 1970);
retrieveStone("The Avengers", "mind", 2012);
retrieveStone("Thor and Rocket", "reality", 2013);
retrieveStone("Black Widow and Hawkeye", "soul", 2014);
checkStoneStatus();
retrieveStone("Hulk", "time", 2012);
battle();
endOfBattle(allies, enemy);
```
