Help with error - comparisons against strings

Asked

Viewed 859 times

-5

Hello, Good night!

I am on a platform of studies in which exercises and tests are performed, the statement is:

Sets the function today Magazine, which receives by parameter a string that informs the day of the week. This function should return"Today is football day!!!" if parameter is "Sunday", otherwise it should return "Today is not football day :(".

I made the following code:

function hojeSeJoga(diaDaSemana) {
    if (diaDaSemana == "domingo") {
        return 'Hoje é dia de futebol!!!';
    } else {
        return 'Hoje não é dia de futebol :('
    }
}

And the platform reports that:

Your solution worked, but there are things to improve

Objectives that were not met:

Today Jooga makes comparisons against strings

Results of the test: Today June("Sunday") should say if you play

Today June("Tuesday") should say that he does not play

What is missing?

Thank you!

  • 2

    May I ask what platform is this? It is raining similar questions here, this same one has been asked in other ways 4 times.

  • Wow, mine is Digital House.

  • 1

    Thank you. These are many similar questions. Perhaps this school is indicating the site for students to ask questions. From what I saw of the questions equal to yours, it is not clear if these requirements (how to avoid comparing to string) are explicit from the beginning. Because if they’re not, I’d consider the exercise bad. Besides, if it’s to avoid comparing it to string, it would be nice to have you explain why, instead of trying to stick a myth in your head. Anyway, good luck in school.

  • They are not clear, the exercise statement is like this. So there are several doubts and errors at the time of the test. Thank you!

  • 1

    @bfavaretto the exercises are all terrible and the impression is that they are deceiving the people who are doing.

  • 1

    It’s really the case that we stay tuned, there’s a lot of junk testing coming from that platform, and I’ve seen a lot of bad tests lately.

Show 1 more comment

1 answer

0


var domingo = "domingo";
var segunda = "segunda";
var terca = "terca";
var quarta = "quarta";
var quinta = "quinta";
var sexta = "sexta";
var sabado = "sabado";
function hojeSeJoga (diaDaSemana) {
  if (diaDaSemana === domingo) {
    return "Hoje é dia de futebol!!!";
  } else {
    return "Hoje não é dia de futebol :(";
  }
}

Use this one that will solve...

  • It worked out! Thank you!

  • Wonderful... tbm am doing these exercises, but I’m standing a little further... rs...

  • Why define this bunch of variable that is not used? If the platform implies comparison of strings, one variable would be enough for "Sunday", right? Type var diaDeFutebol = 'domingo'; if (diaDaSemana === diaDeFutebol) {...

  • I believe you’re right, but tbm am Noob in JS and this was the only solution that the course site accepted...

  • The platform implies with anything bfavaretto , but this form also accepted. Thank you!

  • 1

    @bfavaretto we have noticed this on other issues, there are cases that the platform complains of comparison with literal, as if that alone was a problem. Must be another one of those "good practices,".

Show 1 more comment

Browser other questions tagged

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