Friday, 14 July 2023

currency converter


To use this code, save the HTML code in a file named index.html, the CSS code in a file named styles.css, and the JavaScript code in a file named script.js. Place all three files in the same directory.

Open the index.html file in a web browser, and you should see the GST Calculator tool with colorful styling. Enter the amount and select the GST rate, then click the "Calculate" button to see the calculated GST amount and total amount below the button.


Free Research Preview. ChatGPT may produce inaccurate information about people, places, or facts. ChatGPT May 24 Version



<!DOCTYPE html>
<html>
<head>
  <title>Currency Converter</title>
  <link rel="stylesheet" type="text/css" href="body {
  font-family: Arial, sans-serif;
  background-color: #f5f5f5;
}

.container {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

h1 {
  text-align: center;
  color: #333;
}

.converter {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

input[type="number"], select {
  padding: 10px;
  margin-right: 10px;
  border: 1px solid #ccc;
  border-radius: 3px;
}

button {
  padding: 10px 20px;
  background-color: #4CAF50;
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

button:hover {
  background-color: #45a049;
}

#result {
  text-align: center;
  color: #333;
  font-size: 18px;
}
">
</head>
<body>
  <div class="container">
    <h1>Currency Converter</h1>
    <div class="converter">
      <input type="number" id="amount" placeholder="Enter Amount">
      <select id="fromCurrency">
        <option value="USD">USD</option>
        <option value="EUR">EUR</option>
        <option value="GBP">GBP</option>
        <!-- Add more currencies here -->
      </select>
      <select id="toCurrency">
        <option value="USD">USD</option>
        <option value="EUR">EUR</option>
        <option value="GBP">GBP</option>
        <!-- Add more currencies here -->
      </select>
      <button onclick="convertCurrency()">Convert</button>
    </div>
    <div id="result"></div>
  </div>

  <script src="function convertCurrency() {
  var amount = document.getElementById("amount").value;
  var fromCurrency = document.getElementById("fromCurrency").value;
  var toCurrency = document.getElementById("toCurrency").value;

  var url = `https://api.exchangerate-api.com/v4/latest/${fromCurrency}`;

  fetch(url)
    .then(response => response.json())
    .then(data => {
      var rate = data.rates[toCurrency];
      var convertedAmount = (amount * rate).toFixed(2);
      var result = `${amount} ${fromCurrency} = ${convertedAmount} ${toCurrency}`;

      document.getElementById("result").innerHTML = result;
    })
    .catch(error => {
      console.log("Error:", error);
      document.getElementById("result").innerHTML = "An error occurred.";
    });
}
"></script>
</body>
</html>

No comments:

Post a Comment

configuration of website

Menu Type: Dropdown with Full Width Ensure the navigation items in the dropdown menu contain relevant keywords related to the we...