bank.js

function Checking(amount){
	if(amount){
            this.banlance=amount;
        }else{
            this.banlance=0;
    };
	this.deposit=function(dep){
		this.banlance+=dep;
	};
	this.withdraw=function(dra){
		if(dra>this.banlance){
			console.log("Insufficient funds.");
		}else if(dra<=this.banlance){
			this.banlance-=dra;
		}
	}
	this.toString=function(){
		if(this.banlance){
			console.log('Your Account Banlance is:'+this.banlance)
		}else{
			console.log('No funds left!');
		}
	}
}

var newAccout=new Checking(10000);
newAccout.toString();
newAccout.deposit(8000);
newAccout.toString();
newAccout.withdraw(80000);
newAccout.toString();
console.log(newAccout);

  

posted on 2017-04-01 10:16  carlyin  阅读(206)  评论(0)    收藏  举报

导航