Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

heloeng
Copy link

@heloeng heloeng commented Sep 20, 2023

No description provided.

}

depositarDinheiro(quantidade) {
this.saldo = this.saldo + quantidade

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;

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) {

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)

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)
})

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() {

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,

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants