---
# System prepended metadata

title: Data of My Life

---

# Data of My Life

```:javascript=

var person = {
    name: "Aman",
    role: 'student'
    numberOfSpells: 17,
    knowKillSpell: false, // the kill spell is Aveda Kedavra 
    friend: true,        // but I dont know how to use it!!!
    isAlive: true
}

let arrayPeople = [ person ];

/*
Hi this is Aman! But there's only just me here now. 
Let me introduce you to the people around me.
*/ 

var newPerson = {
    name: "Hermione",
    role: 'student'
    numberOfSpells: 20,
    knowKillSpell: false,
    friend: true,
    isAlive: true
}
arrayPeople.push(newPerson); 

// Now there is me and Hermione here. 
// Let's make this faster and make a function to have other people join us. 

function createNewPerson(personName, personRole,
personNumberOfSpells, personKnowKillSpell, personFriend, personIsAlive) {
    var person = {     
    name: personName;
    role: personRole;
    numberOfSpells: personNumberOfSpells;
    knowKillSpell: personKnowKillSpell;
    friend: personFriend;
    isAlive: personIsAlive;
    }
    
    arrayPeople.push(person); // adds the new person in the people array
}

createNewPerson("Harry","student",18, false, true,true);
createNewPerson("Ron","student",17,false, true,true);
createNewPerson("Lupin","teacher",80, true, true,true);
createNewPerson("Dumbledore","teacher", 100, true, true,true);
createNewPerson("Hagrid","teacher",45, false, true,true);
createNewPerson("Malfoy","student",17, false, false,true);

// Me, Harry, Ron and Hermione are going to go to class now. 
// Malfoy is also in our class. Lets hope we dont fight.

function attendClass(person.name){
    if (person.role == "student") 
        person.numberOfSpells = person.numberOfSpells + 3; 
}

// First we have our class with Professor Lupin. He is my favourite teacher!
attendClass("Aman");            
attendClass("Harry");
attendClass("Hermione");
attendClass("Ron");
attendClass("Malfoy");

function fightCrime() {
  if power > nyc.threatLevel
  then
    nyc.inPeril = 0;
    nyc.threatLevel = 0;
    threatType = "none";
  else
    power = power - 100;
}

/*
Next we have the Care of Magical Creatures class with Hagrid. 
We are going to the forrest to attend his class. 
Thank God Malfoy wont be joining us!
*/

attendClass("Aman");
attendClass("Harry");
attendClass("Hermione");
attendClass("Ron");


// All was going well but suddenly...

createNewPerson("Bellatrix","none", 60, true, false, true);
createNewPerson("Voldemort","none", 98, true, false, true);
createNewPerson("Lucius","none", 50, true, false, true);
createNewPerson("Avery","none", 50, true, true,true);
createNewPerson("Peter","none", 20, true, false, true);

// We are underattack! I have to call more friends to help us!

createNewPerson("Sirius","none", 80, true, true,true);
createNewPerson("McGonagall","teacher", 80, true, true,true);

// Everyone around me is fighting! Oh noooo what will become of us?

function useKillSpell(person1.name,person2.name){
    if (person1.knowKillSpell)
        person2.isAlive = false;
}

var diff = 0;
function difference(person1.name,person2.name){
    diff = person1.numberOfSpells - person2.numberOfSpells;
    return diff;
}

function fight(person1.name,person2.name){
    diff = difference(person1,person2);
    if (person1.friend == person2.friend )
        //nothing happens
    else
        if (math.abs(diff)>10)
            if (diff>0)
                person2.isAlive = false;  
            else
                person1.isAlive = false;
        else
            if (diff>0)
                useKillSpell(person1,person2); // person 2 dies if person 1 has the kill spell
            else
                useKillSpell(person2,person1); // person 2 dies if person 1 has the kill spell      
}

fight("Aman","Malfoy"); //fight is draw
fight("Hagrid","Bellatrix"); //Hagrid dies :(
fight("Sirius,Bellatrix"); //Bellatrix dies
fight("Peter Pettigrew","Ron"); //Ron dies
fight("Lupin", "Lucius");
fight("McGonagall","Avery");
fight("Dumbledore","Voldemort"); //Voldemort dies

/*
With Voldemorts and Bellatrix dead, the enemy surrendered. 
What an eventful day. I am too tired now so going to go.
If you want to see who else survived, check out the people array. 
*/
```