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

  • 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

  • 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...

  • to be done in c language. follow prompt Second Program: triples.c 8. Create a program named...

    to be done in c language. follow prompt Second Program: triples.c 8. Create a program named triples.c "C How to Program", 8th edition, problem 4.27 on page 154. In other editions, it may be on a different page Here's the problem... A right triangle can have sides that are all integers. The set of 3 integers for the sides of a right triangle is called a Pythagorean triple Write a C program to find all of the triples with hypotenuse...

  • Submit Test This Question: 2 pts 11 of 16 (11 complete) This Test: 39 pts possible...

    Submit Test This Question: 2 pts 11 of 16 (11 complete) This Test: 39 pts possible Explain how you would find the distance XY across the lake shown below, and then find XY. 50 m Y 100 m 200 m Which of the following explains how to find the distance XY? O A. Draw a perpendicular segment from Y to the segment representing 200 m. Then draw the segment XY. A right triangle is formed with side lengths 100 m...

  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

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
ADVERTISEMENT