Kelkulator Menghitung Kecepatan Download dengan JavaScript

Kalkulator Menghitung Kecepatan Download dengan JavaScript

Selamat pagi sobat Webbiz, kali ini kita akan share Kelkulator Menghitung Kecepatan Download dengan JavaScript, kalkulator ini akan memberikan anda waktu yang akan akurat berapa lama waktu yang kalian butuhkan untuk melakukan download file, video dan lainnya.

See the Pen Download Time Calculator by WebbizID (@De-Orchids) on CodePen.

JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Download Time Calculator</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        body {
            background-color: #f8f9fa;
            padding: 50px;
        }
        .calculator {
            background: white;
            max-width: 500px;
            margin: 0 auto;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body>

<div class="container">
    <div class="calculator">
        <h2 class="text-center">Download Time Calculator</h2>
        <form id="calcForm">
            <div class="form-group">
                <label for="fileSize">File Size:</label>
                <input type="number" class="form-control" id="fileSize" placeholder="Enter file size">
                <select class="form-control mt-2" id="fileSizeUnit">
                    <option value="1">KB</option>
                    <option value="1024">MB</option>
                    <option value="1048576">GB</option>
                    <option value="1073741824">TB</option>
                </select>
            </div>
            <div class="form-group">
                <label for="downloadSpeed">Download Speed:</label>
                <input type="number" class="form-control" id="downloadSpeed" placeholder="Enter download speed">
                <select class="form-control mt-2" id="speedUnit">
                    <option value="1">KB/s</option>
                    <option value="1024">MB/s</option>
                    <option value="1048576">GB/s</option>
                    <option value="1073741824">TB/s</option>
                </select>
            </div>
            <button type="submit" class="btn btn-primary btn-block">Calculate</button>
        </form>
        <h4 class="text-center mt-4" id="result"></h4>
    </div>
</div>

<script>
    document.getElementById('calcForm').addEventListener('submit', function(event) {
        event.preventDefault();
        
        const fileSize = document.getElementById('fileSize').value * document.getElementById('fileSizeUnit').value;
        const downloadSpeed = document.getElementById('downloadSpeed').value * document.getElementById('speedUnit').value;
        
        const timeInSeconds = fileSize / downloadSpeed;
        const minutes = Math.floor(timeInSeconds / 60);
        const seconds = Math.floor(timeInSeconds % 60);
        
        document.getElementById('result').innerText = `Estimated Download Time: ${minutes} minutes and ${seconds} seconds`;
    });
</script>

</body>
</html>
JavaScript

Semoga bermanfaat..