From f435a6ea09002b7974e2c403c3d668109cf9069a Mon Sep 17 00:00:00 2001
From: leneffets <74921589+leneffets@users.noreply.github.com>
Date: Tue, 26 Nov 2024 08:48:20 +0100
Subject: [PATCH] update currency and output
---
index.html | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/index.html b/index.html
index f5b74de..449226a 100644
--- a/index.html
+++ b/index.html
@@ -75,19 +75,31 @@
Currency and Weight Converter
@@ -150,6 +162,8 @@ Currency and Weight Converter
const priceInSource = parseFloat(document.getElementById('price').value);
const weightInGrams = parseFloat(document.getElementById('weight').value);
const unitWeight = parseFloat(document.getElementById('unitWeight').value);
+ const sourceCurrency = document.getElementById('sourceCurrency').value;
+ const targetCurrency = document.getElementById('targetCurrency').value;
if (isNaN(priceInSource) || priceInSource <= 0) {
document.getElementById('output').innerHTML = 'Please enter a valid price.';
@@ -157,16 +171,16 @@ Currency and Weight Converter
}
const priceInTarget = priceInSource * exchangeRate;
- let output = `Price in target currency: ${priceInTarget.toFixed(2)} ${document.getElementById('targetCurrency').value}`;
+ let output = `Price ${priceInSource} ${sourceCurrency}: ${priceInTarget.toFixed(2)} ${targetCurrency}`;
// Only calculate weight-based values if weight is provided
if (!isNaN(weightInGrams) && weightInGrams > 0) {
const pricePerKg = (priceInTarget / weightInGrams) * 1000;
- output += `
Price per kilogram: ${pricePerKg.toFixed(2)} ${document.getElementById('targetCurrency').value}/kg`;
+ output += `
Price per kilogram: ${pricePerKg.toFixed(2)} ${targetCurrency}/kg`;
if (!isNaN(unitWeight) && unitWeight > 0) {
const priceForUnit = (pricePerKg / 1000) * unitWeight;
- output += `
Price for ${unitWeight}g: ${priceForUnit.toFixed(2)} ${document.getElementById('targetCurrency').value}`;
+ output += `
Price for ${unitWeight}g: ${priceForUnit.toFixed(2)} ${targetCurrency}`;
}
}