Pythagoras Theorem

Explore interactive JavaScript examples for solving triangle problems using the Pythagorean Theorem.

Introduction to Pythagoras Theorem

The Pythagoras Theorem is used to solve problems related to the length of the sides of a right-angled triangle. The formula is:

a² + b² = c²

Where:

  • a is the length of the opposite side
  • b is the length of the adjacent side
  • c is the length of the hypotenuse
Key concepts:
  • Works only for right-angled triangles
  • Hypotenuse is always the longest side
  • Can be used to find any side if the other two are known
  • Practical applications in construction, navigation, and physics
a
b
c

Example 1: Calculate Hypotenuse

Calculate the hypotenuse (c) when given the lengths of the opposite (a) and adjacent (b) sides. The formula is:

c = √(a² + b²)
function calculateHypotenuse() {
    const a = parseFloat(document.getElementById('hyp-a').value);
    const b = parseFloat(document.getElementById('hyp-b').value);
    
    if (isNaN(a) || isNaN(b) || a <= 0 || b <= 0) {
        document.getElementById('hyp-result').textContent = 'Please enter valid positive numbers';
        return;
    }
    
    const c = Math.sqrt(a*a + b*b);
    document.getElementById('hyp-result').textContent = `Hypotenuse (c) = ${c.toFixed(2)}`;
}

Calculate Hypotenuse

Example 2: Calculate Adjacent Side

Calculate the adjacent side (b) when given the lengths of the opposite (a) and hypotenuse (c) sides. The formula is:

b = √(c² - a²)
function calculateAdjacent() {
    const a = parseFloat(document.getElementById('adj-a').value);
    const c = parseFloat(document.getElementById('adj-c').value);
    
    if (isNaN(a) || isNaN(c) || a <= 0 || c <= 0) {
        document.getElementById('adj-result').textContent = 'Please enter valid positive numbers';
        return;
    }
    
    if (c <= a) {
        document.getElementById('adj-result').textContent = 'Hypotenuse must be larger than opposite side';
        return;
    }
    
    const b = Math.sqrt(c*c - a*a);
    document.getElementById('adj-result').textContent = `Adjacent (b) = ${b.toFixed(2)}`;
}

Calculate Adjacent Side

Example 3: Calculate Opposite Side

Calculate the opposite side (a) when given the lengths of the adjacent (b) and hypotenuse (c) sides. The formula is:

a = √(c² - b²)
function calculateOpposite() {
    const b = parseFloat(document.getElementById('opp-b').value);
    const c = parseFloat(document.getElementById('opp-c').value);
    
    if (isNaN(b) || isNaN(c) || b <= 0 || c <= 0) {
        document.getElementById('opp-result').textContent = 'Please enter valid positive numbers';
        return;
    }
    
    if (c <= b) {
        document.getElementById('opp-result').textContent = 'Hypotenuse must be larger than adjacent side';
        return;
    }
    
    const a = Math.sqrt(c*c - b*b);
    document.getElementById('opp-result').textContent = `Opposite (a) = ${a.toFixed(2)}`;
}

Calculate Opposite Side

More Math Examples

Explore more JavaScript math examples to enhance your learning experience: