Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139833

Why this javascript code doesn't run well?

$
0
0

As a starter of JS, I don't know what's wrong with my code. I guess the bug lies on notifyObserver() Because I use console.log at that point but it doesn't output anything. I don't know how to fix.

    constructor(){
        this.numberOfGuests=2;
        this.subscribers=[];
    }
    setNumberOfGuests(x){  
        this.numberOfGuests = x;
        this.notifyObservers({guests:x});
        return x
        // TODO TW1.1
    }
    getNumberOfGuests(){
        return this.numberOfGuests // TODO TW1.1
    }
    addObserver(callback){
        this.subscribers.push();


    }
    notifyObservers(whatHappened){
        for(let i=0; i<this.subscribers.length; i++)
        { 
            let callback= subscribers[i];
            return callback

       }
    }
}
function onModelChange(payload){
   document.body.textContent= payload.guests;
}
model.addObserver(onModelChange);

// initialize the view as before
document.body.textContent= model.getNumberOfGuests();

Viewing all articles
Browse latest Browse all 139833

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>