Exercise error Javascript - true == false

Asked

Viewed 301 times

-1

Hi, can you help me with this mistake? I’m taking an introductory Javascript course on an online teaching platform, and I’m having a problem in an exercise that asks:

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.

Remember that you can do what is needed using Return without using if/Else.

This platform ends up having some demands that even though I am very early I can see are a little unnecessary. My code is like this:

function possoIrAoBanco(diaDaSemana, horaAtual) {
  var domingo = "domingo";
  var segunda = "segunda-feira";
  var terca = "terça-feira";
  var quarta = "quarta-feira";
  var quinta = "quinta-feira";
  var sexta = "sexta-feira";
  var sabado = "sábado";
  return diaDaSemana != sabado || diaDaSemana != domingo && diaDaSemana == segunda || diaDaSemana == terca || diaDaSemana == quarta || diaDaSemana == quinta || diaDaSemana == sexta && horaAtual < 15 && horaAtual > 9;
}

The error that appears is:

inserir a descrição da imagem aqui

What could be wrong?

  • 6

    Yeah, that platform unravels instead of teaching, we get it.

  • Unfortunately... but you can help me with this mistake?

2 answers

1

The problem is in return, as you are working with several conditions in a larger expression with the operators && or ||, the correct is to write each of the two conditions in parentheses. In your case I’d be:

(diaDaSemana != sabado || diaDaSemana != domingo) && (diaDaSemana == segunda || diaDaSemana == terca || diaDaSemana == quarta || diaDaSemana == quinta || diaDaSemana == sexta) && (horaAtual < 15 && horaAtual > 9);

Also, you can decrease it just to:

(diaDaSemana != sabado || diaDaSemana != domingo) && (horaAtual > 9 && horaAtual < 15);
  • I had tried the smallest way and the site did not accept. But with the parentheses it was right! Thank you very much!

  • 1

    Got it. That nothing to see the site. Good luck in studies.

0

function possoIrAoBanco ( diaDaSemana,horaAtual) {
    var naoPode = ('Sábado');
    var naoAbre = ('Domingo');
    return diaDaSemana!= naoPode && diaDaSemana!= naoAbre && horaAtual >=9 
&& horaAtual<=15;

/ / #This way it can also work, it is important that the strings are separate, if it is exercises of the DH platform it is good to have a lot of attention to the details of the statement because they are made so that you have problems and think about them.

Browser other questions tagged

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