Calculator Tools Calculator Tools
Create

Crypto Exchange Calculator

Sep 17, 2023

About this app

A simple and easy-to-use crypto exchange calculator.

Crypto Exchange Calculator 🔀 Crypto Exchange Calculator 🔀 From: To: Amount: Convert

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Crypto Exchange Calculator</title>
<meta name="description" content="A simple and easy-to-use crypto exchange calculator.">
<meta name="keywords" content="crypto, exchange, calculator, conversion, currency">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script type="text/javascript">
try {
const CRYPTOS = ['BTC', 'ETH', 'LTC', 'XRP', 'BCH', 'ADA', 'DOGE'];
let exchangeRate = {};

function getExchangeRate(from, to) {
// Simplified, replace with real API call in production
return Math.random() * (1.5 - 0.5) + 0.5;
}

function calculate() {
const from = document.getElementById('from').value;
const to = document.getElementById('to').value;
const amount = document.getElementById('amount').value;

if (!from || !to || !amount) return;

if (!exchangeRate[from + to]) {
exchangeRate[from + to] = getExchangeRate(from, to);
}

document.getElementById('result').innerText = `You get: ${(amount * exchangeRate[from + to]).toFixed(2)} ${to}`;
}

document.addEventListener("DOMContentLoaded", function() {
CRYPTOS.forEach(crypto => {
document.getElementById('from').innerHTML += `<option value="${crypto}">${crypto}</option>`;
document.getElementById('to').innerHTML += `<option value="${crypto}">${crypto}</option>`;
});
});

} catch (error) {
throw error;
}
</script>

<style>
body {
background: #eee;
font-family: 'Raleway', sans-serif;
}

#main-container {
max-width: 600px;
margin: auto;
padding-top: 100px;
text-align: center;
}

.convert-form {
background: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
}

.convert-form h2 {
margin-bottom: 20px;
}

.convert-form .form-group {
margin-bottom: 20px;
}

.convert-form button {
background: #0275d8;
color: #fff;
}

.result {
margin-top: 20px;
font-size: 24px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<div class="convert-form">
<h2>🔀 Crypto Exchange Calculator 🔀</h2>

<div class="form-group">
<label for="from">From:</label>
<select id="from" class="form-control"></select>
</div>

<div class="form-group">
<label for="to">To:</label>
<select id="to" class="form-control"></select>
</div>

<div class="form-group">
<label for="amount">Amount:</label>
<input type="number" id="amount" class="form-control" step="0.01" min="0">
</div>

<button onclick="calculate()" class="btn btn-block">Convert</button>

<div id="result" class="result"></div>
</div>
</div>
</body>
</html>