-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resolução do exercício - Heloiza Mendes #18
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
depositarDinheiro(quantidade) { | ||
this.saldo = this.saldo + quantidade |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tem uma forma de escrever essa atribuição mais simplificada.
this.saldo += quantidade
O funcionamento é o mesmo, só é uma syntax sugar para simplificar a codificação.
sacarDinheiro(quantidade) { | ||
if (quantidade <= this.saldo) { | ||
//tirar do saldo | ||
this.saldo = this.saldo - quantidade; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aqui também pode se aplicar a syntax sugar.
return this.limite | ||
} | ||
|
||
depositarDinheiro(quantidade) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uma sugestão para a função depositar é verificar se quantidade é maior que zero, se o valor for menor ou igual a zero dispara uma throws. Algo semelhante com isso:
realizarDeposito(quantidade){
if(quantidade>0){
this.saldo+=quantidade;
}else{
throw new Error("Valor inválido");
}
return this.consultarSaldo();
}
É só uma sugestão mesmo.
|
||
|
||
|
||
const contaUsuario = new ContaBancaria("Heloiza", 1000, 200) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talvez fosse interessante apagar esses console.log para deixar mais clear.
test("Validar saldo, após depósito na conta", () => { | ||
expect(contaUsuario.depositarDinheiro(500)).toEqual(1500) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se você for implementar minha sugestão da função depositarDinheiro, sugiro fazer mais um teste para quando o usuário tentar depositar um valor inválido.
this.limite = limite; | ||
} | ||
|
||
consultarSaldo() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Muito legal esse padrão de usar verbos em funções deixa o código muito legível.
@@ -0,0 +1,84 @@ | |||
/* Exercicio Proposto: Considere um objeto que represente uma conta bancária, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talvez também apagar esses comentários seja interessante.
No description provided.