Exercise of conditionals

Asked

Viewed 331 times

0

I’m having trouble with this next army:

Set the podeSubir function, receiving 3 parameters: highPessoa (number), timeCompania (boolean), temProblemaCardiaco (boolean). Take into account the necessary conditions mentioned below:

  • Reach a height of at least 1,5 m (or 1,2 m if accompanied by an adult)
  • Not having any heart problem.

The code went like this

function podeSubir(alturaPessoa, vemComCompania, temProblemaCardiaco) {
  return (
    (alturaPessoa <= 1.2 && vemComCompania) ||
    (alturaPessoa >= 1.5 && !vemComCompania) && !temProblemaCardiaco
  );
}


console.log(podeSubir(1.5, false, false))
console.log(podeSubir(1.7, false, true))
console.log(podeSubir(1.2, true, false))
console.log(podeSubir(1.2, false, false))
console.log(podeSubir(1.1, true, false))

But the problem is I can’t get past the last of the validations:

  • a person who is 1.5m, is not accompanied by an adult and has no heart problems can rise in attraction -> correct
  • a person who is 1.7m, is not accompanied by an adult and has heart problems can not rise in attraction -> correct
  • a person who is 1.2m, is accompanied by an adult and has no heart problems can rise in attraction -> correct
  • a person who is 1.2m, is not accompanied by an adult and has no heart problems can not rise in attraction -> correct
  • a person who is 1.1m, is accompanied by an adult and has no heart problems can not rise in attraction -> is returning true and the correct is false

Thank you so much for all your attention and help

  • I edited my doubt better, I hope it has become more coherent and sorry for any confusion

1 answer

1


It makes sense, since the comparison you are making is <=1.2 (less than or equal to 1.2) and 1.1 enters this condition, just change to >= 1.2 I suppose

  • Thank you very much, Adiel. The mistake was exactly that and ended up passing unnoticed by me. Thank you again for understanding my doubt, which at first was worded in a confusing way

  • Could you accept my answer as the best answer then? Thank you

  • 1

    Okay, I’ve done as requested. I’m still getting used to the platform and thank you for the patience you had with me

Browser other questions tagged

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