Can I go to the bank?

Asked

Viewed 155 times

-4

I have a problem in an exercise of an online course that I am doing, I have tried in every way I could reach but it does not accept. I don’t know where I’m going wrong. Exercise is down, along with my code.

Enunciation:

Now let’s create a function that tells us if the bank is closed?

First of all we need to know that a bank is closed when it is weekend (Saturday or Sunday) and is not in bank hours (9 to 15hs).

Set the function possibleIrAoBanco which, receive two parameters, the first is diaDaSemana (string) and the second timeAtual(number), the function must return true, only if the database is open.

Example:

possoIrAoBanco("segunda-feira", 10); // true, é um dia da semana e está no horário bancário, 10hs
possoIrAoBanco("terça-feira", 18); // false, é dia da semana e NÃO está no horário bancário, 18hs
possoIrAoBanco("Sábado", 11); // false, é fim de semana

Remember that you can do what is necessary using the return without making use of if/else.

Error that appear are this :

The execution of the function possoIrAoBanco('Segunda', 10) must return true The execution of the function possoIrAoBanco('Terça', 18) must return false
The execution of the function possoIrAoBanco('Sábado', 11) must return false The execution of the function possoIrAoBanco('Domingo',13) must return false

My code is like this:

inserir a descrição da imagem aqui

2 answers

1

Yesterday I made that same code, I hope it helps you and welcome the platform.

function possoIrAoBanco(diaDaSemana, horaAtual) {
  const diasFuncionamentoBanco = ['segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira'];

  const diaDeFuncionamento = diasFuncionamentoBanco.indexOf(diaDaSemana) !== -1;

  const horarioDeFuncionamento = horaAtual >= 9 && horaAtual <= 15;

  return diaDeFuncionamento && horarioDeFuncionamento;
}

console.log(`domingo as 8: ${possoIrAoBanco('domingo', 8)}`);
console.log(`segunda as 9: ${possoIrAoBanco('segunda-feira', 9)}`);
console.log(`terça as 10: ${possoIrAoBanco('terça-feira', 10)}`);
console.log(`quarta as 20: ${possoIrAoBanco('quarta-feira', 20)}`);
console.log(`quinta as 12: ${possoIrAoBanco('quinta-feira', 12)}`);
console.log(`sexta as 15: ${possoIrAoBanco('sexta-feira', 15)}`);
console.log(`sabado as 14: ${possoIrAoBanco('sabado', 14)}`);

-1

Natalia, see if the code below works:

function possoIrAoBanco(diaDaSemana, horaAtual){
 return diaDaSemana == 6 || horaAtual == 10; 

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.