Question

Write a JavaScript function called getHypotenuse that returns the length of the hypotenuse of a right...

Write a JavaScript function called getHypotenuse that returns the length of the hypotenuse of a right triangle given the length of the other two sides. You can utilize the Pythagorean Theorem. Test your function with the following data.

getHypotenuse(3, 4) should return 5

getHypotenuse(6, 8) should return 10

Rewrite the above function as an arrow function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE ( Javascript implemented in head section using script tag ) :

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

<script>

// Function Definition takes two input parametes

// i.e, the length of two other sides of the right angled triangle

function getHypotenuse(a,b) {

return Math.sqrt(a*a + b*b); // return hypotenuse using pythagorean theorem

}

document.write(getHypotenuse(3,4)+ "\n"); // => 5

document.write(getHypotenuse(6,8)+ "\n" ); // => 10

// Rewrite getHypotenue using arrow function

// parameters are a and b

var hyp = (a,b) => Math.sqrt(a*a + b*b);

// test arrow function with 3, 4 as parameters

document.write(hyp(3,4));

</script>

</head>

<body>

</body>

</html>

OUTPUT :

Add a comment
Know the answer?
Add Answer to:
Write a JavaScript function called getHypotenuse that returns the length of the hypotenuse of a right...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ The length of the hypotenuse of a right-angled triangle is the square root of the...

    c++ The length of the hypotenuse of a right-angled triangle is the square root of the sum of the squares of the other two sides. Write a function calcH that accept two doubles as function arguments and returns a double. Prompt the user for the length of base and the perpendicular side of the triangle. Use the pow and sqrt functions from cmath to perform the calculations

  • The square of the hypotenuse equals the sum of the squares of the other two sides...

    The square of the hypotenuse equals the sum of the squares of the other two sides of a right triangle is called Pythagorean theorem. true or false

  • sides   of   a   right   triangle,   and   a   string,   which   is   either   “S”   or   “H”,   and   re

    sides   of   a   right   triangle,   and   a   string,   which   is   either   “S”   or   “H”,   and   returns   the   length   of   the   third   side   of   the   triangle.       “S”   indicates   that   the   third   length   (i.e.   the   value   to   be   computed)   is   the   length   of   a   leg,   and   “H”   indicates   that   the   third   length   (i.e.   the   value   to   be   computed)   is   the   length   of   the   hypotenuse.   Name   your   function   getLength(p1,   p2,   myString).       The   result   should   be   rounded   to   the   nearest   tenth.      ...

  • Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right...

    Write Python expressions corresponding to the following statements: The length of the hypotenuse in a right triangle whose other two sides have lengths a and b The value of the expression that evaluates whether the length of the above hypotenuse is 5 The area of a disk of radius a The value of the Boolean expression that checks whether a point with coordinates x and y is inside a circle with center (a, b) and radius r

  • Python Programming 4th Edition Write a program that calculates the length of a right triangle's hypotenuse....

    Python Programming 4th Edition Write a program that calculates the length of a right triangle's hypotenuse. Hints: Define main() program Get the length of the triangle’s two sides (user input) Call math function to calculate the length of the hypotenuse. The output should look like as follows: The length of the hypotenuse is 12.041594578792296

  • Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called...

    Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called isright, that takes three inputs, a, b, and c, and determines whether they are could be the lengths of the sides of a right triangle; the output, y, will be set equal to the following: i). -1 if at least one of the values is not positive. Also, only for this case, have the function print out an error message, which states "At least...

  • In entry level form Develop a C# console application that computes the hypotenuse of a right...

    In entry level form Develop a C# console application that computes the hypotenuse of a right triangle. The computation of the hypotenuse of a right triangle is based on the Pythagorean Theorem: c2 = a2 + b2 and the hypotenuse, c ("long side") of the triangle can be computed with the formula the hypotenuse is equal to the square root of the side a squared plus side b squared. The application should take as many side pairs inputs as the...

  • Without using the Pythagorean theorem, prove that two right triangles are congruent if the hypotenuse and...

    Without using the Pythagorean theorem, prove that two right triangles are congruent if the hypotenuse and leg of one are equal to the hypotenuse and leg of the other.   Do this with placing the triangles so that there equal legs coincide and their right legs are adjacent. This will form a large isoceles triangle. Use this to show that the given triangles are congruent by AAS.  

  • write an algorithm function called balance() in javascript that takes in a string and returns a...

    write an algorithm function called balance() in javascript that takes in a string and returns a strinf with balanced parantheses only. the string should be able to contain only parantheses, numbers, and letters. include comments of each portion of your code balance(“()()”) should return “()()” balance(“())”) should return “()” balance(“a(b)c”) should return “a(b)c” balance(“a(b)c())”) should return “a(b)c()”

  • Write the java program: A right triangle can have sides whose lengths are all integers. The...

    Write the java program: A right triangle can have sides whose lengths are all integers. The set of three integer values for the length of the sides of a triangle is called a Pythagorean triple. The length of the three sides must satisfy the relationship that the sum of the squares of the sides is equal to the square of the hypotenuse. Write a Java application that prompts the user for an integer that represents the largest side value and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT