micro:bit MakeCode problem -- Why does this happen?

26 views Asked by At

I have looked, looked, and looked for a solution, I have tried booleans then tried || (which is apparently "OR" in typescript, which is MakeCode's main language for the JavaScript) It's a weird problem I get. Anyone know why this happens? micro:bit makecode site

// important
let mood = 100;
let sleep = 100;
let hunger = 100;
let happy = false;
let sad = false;
let asleep = false;
let angry = false;

function check() {
    if(mood >= 80 || sleep >= 80 || hunger >= 80){
        if(!happy){
            basic.showIcon(IconNames.Happy) 
            happy = true;
            sad = false;
            asleep = false;
            angry = false;
        }
    }else{
        if(mood >= 50 || sleep >= 50 || hunger >= 50){
            if(!sad){
                basic.showIcon(IconNames.Sad);
                happy = false;
                sad = true;
                asleep = false;
                angry = false;
            }
        }else{
            if(mood >= 25 || sleep >= 25 || hunger >= 25){
                if(!asleep){
                    basic.showIcon(IconNames.Asleep);
                    happy = false;
                    sad = false;
                    asleep = true;
                    angry = false;
                }
            }else{
                if(!angry){
                    basic.showIcon(IconNames.Angry);
                    happy = false;
                    sad = false;
                    asleep = false;
                    angry = true;
                }
            }
        }
    }

    if(randint(1,10)==1){
        mood -= 5;
        hunger -= 10;
        sleep -= 1;
    }
    console.log("Mood: " + mood + ", Hunger: " + hunger + " Sleep: " + sleep);
}

basic.forever(check);
0

There are 0 answers