# Doodle 002 - Data of My Life
### Disneyland Day Trip
Below is a day that I spent in Shanghai Disneyland Park last week.
### Description
The main character here is Susan(sz).
- sz has three variables, name, isHungry and isTired.
- disneyland specifies its location and attractions, which is a list of attractions.
- journey includes the day, tirednessLevel, hungerLevel, number and a list of attractions visited.
Each time Susan takes a ride, her hunger and tiredness levels increase.
By definition,
```
hunger level += wait time
tiredness level += wait time * 2
```
When the hunger level exceeds MAXHUNGER, she goes to eat. Eating reduces her hunger level to 0. When the tiredness level exceeds MAXTIREDNESS, she goes home.
### Code
```:javascript=
let MAXHUNGER = 100
let MAXTIREDNESS = 600
let sz = {
name: "Susan",
isHungry: false,
isTired: false,
}
let disneyland = {
city: "Shanghai",
// a list of attractions and the wait time
attractions: [["Dumbo the Flying Elephant", 30],
["Fantasia Carousel", 40],
["Peter Pan's Flight", 30],
["Soaring Over the Horizon", 60],
["Buzz Lightyear Planet Rescue", 10],
["TRON Lightcycle Power Run", 30],
["Roaring Rapids", 50],
["Seven Dwarfs Mine Train", 100]],
}
let journey = {
day: "Thursday",
// tirednessLevel = sum of double the wait time
tirednessLevel: 0,
// hungerLevel = sum of wait time
hungerLevel: 0,
numOfAttrVisited: 0,
attrVisited: []
}
// main function
function dayTrip() {
// enter at the gate
let nameChecked = nameCheck(sz)
// check if the tourist entered is Susan
if (nameChecked == true) {
if (sz.isTired == false) {
// as long as Susan is not tired,
// Suasan stays in the park and
// visits attractions
haveFun();
}
}
else {
// nothing happens here
}
}
// helper functions
function haveFun() {
while (sz.isTired == false && sz.isHungry == false) {
visitAttr();
}
if (sz.isHungry) {
// when hungerLevel becomes 0
// Susan can keep having fun
eat();
haveFun()
}
else {
// when tirednessLevel goes to max
goHome();
}
}
function visitAttr() {
let attr = disneyland.attractions.pop();
journey.attrVisited.push(attr[0]); //updates the list
journey.hungerLevel += attr[1]; //updates hungerLevel and tirednessLevel
journey.tirednessLevel += attr[1]*2;
checkTired();
checkHungry();
journey.numOfAttrVisited++; //updates the number of attractions visited
}
function eat() {
journey.hungerLevel = 0;
sz.isHungry = false;
}
function goHome() {
// Susan returns home
}
function checkTired() {
if (journey.tirednessLevel > MAXTIREDNESS){
sz.isTired = true;
}
else {
sz.isTired = false;
}
}
function checkHungry() {
if (journey.hungerLevel > MAXHUNGER){
sz.isHungry = true;
}
else {
sz.isHungry = false;
}
}
function nameCheck(tourist){
return Boolean(tourist.name == "Susan");
}
dayTrip();
```
### Note
I added some console.log to test this program and when I ran ```dayTrip();``` console showed me a full schedule of my Disneyland trip. It was fun playing with the numbers to change the number of times it calls ```eat();```. The link to the my codepen for this doodle is here: https://codepen.io/sx2278/pen/mdErJOX.