Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
2.2 kB
1
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Luas & Keliling Segitiga</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin: 50px;
        }

        input {
            padding: 5px;
            margin-bottom: 10px;
        }

        button {
            padding: 8px 15px;
            cursor: pointer;
        }
    </style>
</head>
<body>

    <h2>Hitung Luas & Keliling Segitiga</h2>

    <label for="base">Masukkan Panjang Alas:</label>
    <input type="number" id="base" placeholder="Panjang Alas">

    <label for="height">Masukkan Tinggi:</label>
    <input type="number" id="height" placeholder="Tinggi">

    <br>

    <button onclick="hitungLuas()">Hitung Luas</button>
    <button onclick="hitungKeliling()">Hitung Keliling</button>

    <br>

    <p id="result"></p>

    <script>
        function hitungLuas() {
            var base = parseFloat(document.getElementById('base').value);
            var height = parseFloat(document.getElementById('height').value);

            if (!isNaN(base) && !isNaN(height)) {
                var area = 0.5 * base * height;
                document.getElementById('result').innerHTML = 'Luas Segitiga: ' + area;
            } else {
                document.getElementById('result').innerHTML = 'Masukkan angka valid untuk panjang alas dan tinggi.';
            }
        }

        function hitungKeliling() {
            var base = parseFloat(document.getElementById('base').value);
            var height = parseFloat(document.getElementById('height').value);

            if (!isNaN(base) && !isNaN(height)) {
                var hypotenuse = Math.sqrt(base * base + height * height);
                var perimeter = base + height + hypotenuse;
                document.getElementById('result').innerHTML = 'Keliling Segitiga: ' + perimeter;
            } else {
                document.getElementById('result').innerHTML = 'Masukkan angka valid untuk panjang alas dan tinggi.';
            }
        }
    </script>

</body>
</html>
Leave a Comment