Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

Create a html code for Pythagoras

  1. User

    Create a html code for Pythagoras

  2. Assistant
        h1 {
            text-align: center;
        }
        
        .pythagoras {
            margin: 0 auto;
            width: 400px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f5f5f5;
        }
        
        label {
            font-weight: bold;
        }
        
        input[type="number"] {
            width: 100%;
            padding: 6px;
            margin-bottom: 10px;
            border: 1px solid #ddd;
            border-radius: 3px;
        }
        
        button.calculate {
            display: block;
            margin: 0 auto;
            padding: 10px 20px;
            font-weight: bold;
            border: none;
            border-radius: 3px;
            background-color: #4CAF50;
            color: white;
            cursor: pointer;
        }
    </style>
    
        <label for="b-side">Side b:</label>
        <input type="number" id="b-side" placeholder="Enter the length of side b">
        
        <button class="calculate" onclick="calculatePythagoras()">Calculate</button>
        
        <p id="result"></p>
    </div>
    
    <script>
        function calculatePythagoras() {
            var a = parseFloat(document.getElementById('a-side').value);
            var b = parseFloat(document.getElementById('b-side').value);
            
            if (isNaN(a) || isNaN(b)) {
                document.getElementById('result').textContent = "Please enter valid numbers for side a and side b.";
            } else {
                var cSquared = Math.pow(a, 2) + Math.pow(b, 2);
                var c = Math.sqrt(cSquared);
                document.getElementById('result').textContent = "The length of the hypotenuse (side c) is: " + c.toFixed(2);
            }
        }
    </script>