Calculating Javascript false/rue relationship

Asked

Viewed 2,656 times

-2

Could help me solve this question, it should return false/true!

We need to create a function that checks if two people are half brothers!

In order for you to solve this exercise, we have defined for you the functions maeDe and paiDe, which, by receiving a child (string), returns the name (string) of the mother or father as appropriate. Example:

paiDe(cleoPires) "Fábio Júnior" maeDe(cleoPires) "Glória Pires" Now it is your turn to create the functions: temAMesmaMae who has two children by parameter and will return true oufalse if they actually share the same mother. Knowing this you can use the function we give you maeDe.

temOMesmoPa that like the previous one, takes two children by parameter and returns true oufalse if they share the same father. Knowing this you can use the function we give you paiDe.

And We Plan, that by receiving two children per parameter, tell us if they are in fact half-siblings. You should use the two previous functions here.

function temAMesmaMae(sandy,junior){
  var maeDe(sandy) = "Noely";
  var maeDe(junior) = "Noely";
  return maeDe (sandy) == maeDe ("junior"); 
}

function temOMesmoPai(cleoPires,fiuk){
  var paiDe(cleoPires) = "Fábio Junior";
  var paiDe(fiuk) = "Fábio Junior";
  return paiDe (cleoPires) == paiDe ("fiuk");
}

function saoMeioIrmaos (cleoPires, fiuk){
  var paiDe(cleoPires) = "Fábio Junior";
  var maeDe(cleoPires) = "Glória Pires";
  return maeDe(cleoPires) != maeDe "fiuk";
}

1 answer

3

In Javascript it is better to use operators === and !== when comparing.

The function temAMesmame takes 2 strings and compares the received function values maedan returning a Boolean.

function temAMesmaMae(filho1, filho2) {
  return maeDe(filho1) === maeDe(filho2);
}

The function temOMesmoPai takes 2 strings and compares the values received from the function paida returning a Boolean.

function temOMesmoPai(filho1, filho2) {
  return paiDe(filho1) === paiDe(filho2);
}

The function salt takes 2 strings, stores the values received from the functions temAMesmame and temOMesmoPai in the variables but and parents and it will return true if the but are different from parents or vice versa, in other cases return false.

function saoMeioIrmaos(filho1, filho2) {
  const maes = temAMesmaMae(filho1, filho2);
  const pais = temOMesmoPai(filho1, filho2);

  return maes !== pais;
}

Browser other questions tagged

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