---
# System prepended metadata

title: Doodle 02 - Data of My Life

---


# Doodle 02 - Data of My Life

#### By Yan Wang, October 25th
---

```:javascript=

let name = "Yan Wang";
let energy = 50;
let isTired = false;

// Yan is so happy every time she eats a meal that
// she will randomly do one of a series of 
// activities unless she gets tired

let activities = {
    cost: 50, //each activity will cost 50 energy points
    name: ["singing", "dancing", "coding", "drawing"]
}

function rest() {
    energy = energy + 20;
    isTired = false;
}

function doActivity(currentEnergy){
    if currentEnergy > activities.cost
    then
        // energy - 50
        currentEnergy = currentEnergy - activities.cost;
        // take a random index 
        int randomIndex = rand.nextInt(activities.name.size());
         // get the random activity
            activity = activities.name.get(randomIndex);
        print(activity);
    else // Send a warning message and call the rest function
        isTired = true;
        print("I'm tired! Time to take a rest!");
        rest();
}

// Breakfast time
energy = energy + 20; // 70

// Call function to do a activity
doActivity(energy); // energy=70-50=20

// Lunch Time
energy = energy + 30; // 50

// Call function twice to do two activities in the afternoon
doActivity(energy); // energy=50-50=0
doActivity(energy); // failed since isTired=True

// Energy back to 20 due to the rest function

// Dinner time
energy = energy + 30; // 50


// Call function to do a activity
doActivity(energy); // energy=50-50=0

// Bed Time
energy = energy + 50; // 50

// Ready for a new day

```