9

so i have to practice on codewars for homework and my code.. doesnt work! what a surprise. i was wondering if anyone could tell me whats wrong since yall are professionals. its probably a stupid mistake. this is the challenge: Implement a method that excepts three integer values a, b, c. The message return true if a triangle can be built with the sides of given length and false in any other case.

Comments
  • 31
    1) Pythagoras' theorem only holds true for a right triangle, not for all triangles.

    2) You can't rely on c always being the hypotenuse in a right triangle. Hint: the hypotenuse in a right triangle is always the longest side.

    3) = and == and === are different things.
  • 3
    @Fast-Nop right, thanks! now i really feel dumb haha
  • 5
    Found some click bate site with the rules: https://sciencing.com/rules-length-...
  • 8
    Use the law of sines.
    sin(a) / a = sin(b) / b = sin(c) / c
  • 8
    The sum of 2 sides of a triangle is always larger than the remaining side. So I think this should work

    return a+b > c && a+c > b && b+c>a
  • 3
  • 1
    It's because you tryin' to do math in JavaScript!

    xD
  • 1
    @radekwlsk it should be &&. Consider lengths 4, 2, 6 according to you it will give true because 4+6>2 but 4+2!>6 therefore, it should be false
  • 0
    @monzrmango input is lengths, not angles.
  • 2
    Just a tip to prettify your code. You don't need to use an if-else block there. "If <condition> then TRUE else FALSE" it's equivalent to "return <condition>".
  • 0
    Sort the inputs.

    The largest value (the last entry of the sorted array, side_lengths[2], for example) must be less or equal (operator <=) to the sum of the first two (side_lengths[0] + side_lengths[1]).
  • 0
    @irene It does not look like a triangle but by definition, it still is one.
  • 0
    @musma shhh, it’s precious when they are at that stage.
Add Comment