Created
May 6, 2014 05:14
-
-
Save valdiney/d2d106190d92366c43a1 to your computer and use it in GitHub Desktop.
Função construtora simulando uma conta bancaria.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function() { | |
"use strict" | |
function Conta( numero ) { | |
var saldo = 0; | |
this.numero = numero; | |
this.saldo = saldo; | |
} // end ... | |
Conta.prototype.depositar = function( valor ) { | |
var deposito = this.saldo += valor; | |
} // end... | |
Conta.prototype.sacar = function( valor ) { | |
if ( this.saldo > valor ) { | |
var sacando = this.saldo -= valor; | |
return sacando; | |
} | |
else if ( this.saldo === 0 ) { | |
console.log('Seu Saldo está zerado.'); | |
} | |
else if ( valor > this.saldo ) { | |
console.log('Você não tem saldo suficiente para sacar ' + valor + ' Reais'); | |
} | |
} // end... | |
Conta.prototype.extrato = function() { | |
if ( this.saldo === 0 ) { | |
console.log('Numero da Conta: ' + this.numero + ' Seu Saldo está zerado.'); | |
} | |
else { | |
console.log('Numero da Conta: ' + this.numero + ' Saldo Atual: ' + this.saldo + ' Reais'); | |
} | |
} // end... | |
var novaConta = new Conta(5445454545,0); | |
novaConta.depositar(50); | |
novaConta.sacar(10); | |
novaConta.extrato(); | |
} // end... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment