HTML:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Currency Converter</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h1>Currency Converter</h1> <label for="amount">Enter Amount:</label> <input type="number" id="amount" placeholder="Enter amount"> <label for="fromCurrency">From:</label> <select id="fromCurrency"> <option value="USD">USD</option> <option value="EUR">EUR</option> <option value="GBP">GBP</option> </select> <label for="toCurrency">To:</label> <select id="toCurrency"> <option value="USD">USD</option> <option value="EUR">EUR</option> <option value="GBP">GBP</option> </select> <button onclick="convertCurrency()">Convert</button> <p id="result"></p> </div> <script src="script.js"></script> </body> </html>
CSS:
body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f7f7f7; } .container { max-width: 400px; margin: 20px auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h1 { text-align: center; } label, select, input, button { display: block; margin-bottom: 10px; width: 100%; padding: 8px; border-radius: 4px; box-sizing: border-box; } button { background-color: #007bff; color: #fff; border: none; cursor: pointer; } button:hover { background-color: #0056b3; }
JAVASCRIPT:
function convertCurrency() { const amount = document.getElementById('amount').value; const fromCurrency = document.getElementById('fromCurrency').value; const toCurrency = document.getElementById('toCurrency').value; // Replace this logic with actual currency conversion API const conversionRate = 1.2; // Example conversion rate for demonstration const result = (amount * conversionRate).toFixed(2); document.getElementById('result').innerHTML = `${amount} ${fromCurrency} = ${result} ${toCurrency}`; }
Try to answer about this code:
What does the HTML element <select> represent in the code?
It defines a text input field.
It creates a drop-down list of options.
It displays a heading in the document.
It represents a button for form submission.
What JavaScript function is called when the "Convert" button is clicked?
calculateExchange()
convertCurrency()
updateResult()
getConversionRate()
What does the <meta charset="UTF-8"> tag in the HTML code signify?
It sets the language of the document to English.
It defines the character encoding for the document as UTF-8.
It specifies the title of the document.
It links an external stylesheet to the document.
What does the CSS property border-radius: 4px; do in the provided code?
It sets the border width to 4 pixels.
It rounds the corners of various elements.
It adds a shadow effect to the container.
It changes the font size of the text.