af2111: Problem mit NaN

Beitrag lesen

Okay,

danke für den Tipp.

Ich habe das Problem jetzt so gelöst:

let student = {

    getFullname: function () {
        alert("Er heißt " + this.firstname + " " + this.lastname);
    },
    altern: function () {
        let erstsemesterAlter = this.alter;
        let that = this;

        console.log(erstsemesterAlter);
        setInterval(function () {

            that.alter = that.alter + 1;
            console.log(that.alter);
            if (that.alter - erstsemesterAlter == 8) {
                alert("Doktor in " + that.Fach + "!");

            }
        }, 1000);
    }


}

let max = {
    firstname: "Max",
    lastname: "Mustermann",
    Fach: "Informatik",
    alter: 23
};

let lea = {
    firstname: "Lea",
    lastname: "Mustermann",
    Fach: "Mathematik",
    alter: 19
};
max.__proto__ = student;
lea.__proto__ = student;


lea.altern();