हमें एक JavaScript फ़ंक्शन लिखना है जो दो संख्याएँ लेता है। पहली संख्या समकोण त्रिभुज के आधार की लंबाई दर्शाती है और दूसरी लंबवत (perpendicular)। फ़ंक्शन को फिर इन मानों के आधार पर कर्ण की लंबाई की गणना करनी चाहिए।
उदाहरण के लिए -
यदि आधार = 8, लंबवत = 6
तो आउटपुट 10 होना चाहिए
उदाहरण
निम्नलिखित कोड देखें:
const base = 8;
const perpendicular = 6;
const findHypotenuse = (base, perpendicular) => {
const bSquare = base ** 2;
const pSquare = perpendicular ** 2;
const sum = bSquare + pSquare;
const hypotenuse = Math.sqrt(sum);
return hypotenuse;
};
console.log(findHypotenuse(base, perpendicular));
console.log(findHypotenuse(34, 56));
आउटपुट
कंसोल पर निम्नलिखित आउटपुट प्राप्त होगा:
10 65.5133574166368