---
# System prepended metadata

title: Doodle 02 - Data Model of My Life

---

# Doodle 02 - Data Model of My Life
### Zhiyin Wang, Qinya Xu
---
### Data of A Puppy's Life
```:javascript=
let puppy = {
    name: "Harry",
    age:2,
    isHungry: true,
    happiness: 70,
    power: 150;
};

let phaseOfDay = ["morning", "afternoon", "evening"]；


// It's morning now.  
let currentIndex = 0;
currentPhase = phaseOfDay[currentIndex];

wakeUp(); //Harry wakes up.
ownerAwake = false;

function wakeUpOwner() {
    if (ownerAwake === false) {
        bark();
        ownerAwake = true;
    } else {
        shakeTail();
    }
};
//Harry will bark to wake the owner up. If the owner is awake, Harry will be very happy and shake his tail. 
wakeUpOwner(); //Harry wakes up the owner

//Time for breakfast!
function checkFood() {
    if (food <= 50) {
        bark(); //Harry is unhappy and barks!
        food += 50;
    } else {drool()}
}; //Harry will check whether there is food in his bowl. If there is not, he will bark to notice the owner; if there is food, he will droll and wait for the owner's command.
checkFood();

function eatBreakfast() {
    puppy.isHungry = false;
    puppy.happiness += 50;
    puppy.power += 100;
};

if (puppy.isHungry === true) {
    checkfood();
    eatBreakfast();
} else {
    puppy.happiness -= 20;
    //Watching food when you are not hungry is painful!!
    puppy.power -= 50; //Weak Dog :( !
};

function nextPhase() {
    if(currentIndex === 2) {
        currentIndex = 0;
    } else {
        currentIndex++;
    }
    currentPhase = phaseOfDay[currentIndex];
};
//reference: Jin's Lecture: https://www.youtube.com/watch?v=iROHdJjio2U

nextPhase(); //It's afternoon now.
goForAWalk(); //Harry goes for a walk in the afternoon.

let anotherDog = {
    name: Voldemort，
    age: 4,
    power: 300,
    happiness: 250，
};

function meetAnotherDog() {
    if anotherDog.happiness > puppy.happiness {
        fight(); //Harry is a mean dog. He cannot see others live happier than he is.
    }; else {
        puppy.happiness += 50;
    }
};
//When Harry meets another dog. Depending on the happiness of that dog, Harry decided whether to fight.

meetAnotherDog(); //Harry meets another dog and decides whether to fight.


nextPhase(); //It's now evening.
puppy.isHungry = true; //It's dinner time! Harry is very hungry.

var  dinnerChoices = [
 {
  name: "can",
  calories: 400,
  isEatableForDog: true，
  happiness: 20,
  power += 150
 },
 {
  name: "chocolate",
  calories: 200,
  isEatableForDog: false，
  happiness: 0, //Harry will die!
  power -= 1000
 },
 {
  name: "treat",
  calories: 100,
  isEatableForDog: true，
  happiness: 100,
  power += 50
 }
];

function eatDinner() {
    if (dinnerChoices[dinnerIndex].isEatableForDog === true) {
        puppy.happiness += dinnerChoices[dinnerIndex].happiness;
        puppy.power += dinnerChoices[dinnerIndex].power;
        puppy.isHungry = false;
    } else {
        puppy.happiness -= 100;
        refuseToEat();
    }
}; 
//The owner chooses the food for dinner (dinneIndex represents the index of the dinnerChoices array, i.e., 0, 1, 2. If eatable, Harry's happiness and power will raise, if uneatble, Harry's happiness level drop and refuse to eat the dinner.
eatDinner()

sleep(); //Harry falls into sleep and a new day routine will begin.
```