Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Tab switching
+ const tabs = document.querySelectorAll('.tab-btn');
+ const calculators = document.querySelectorAll('.calculator');
+
+ tabs.forEach(tab => {
+ tab.addEventListener('click', () => {
+ tabs.forEach(t => t.classList.remove('active'));
+ calculators.forEach(c => c.classList.remove('active'));
+
+ tab.classList.add('active');
+ document.getElementById(tab.dataset.tab).classList.add('active');
+ });
+ });
+
+ // Date Calculator
+ const calculateDate = () => {
+ const startDate = new Date(document.getElementById('start-date').value);
+ const endDate = new Date(document.getElementById('end-date').value);
+
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
+ document.getElementById('date-result').textContent = 'Please select valid dates';
+ return;
+ }
+
+ const diffTime = Math.abs(endDate - startDate);
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
+
+ document.getElementById('date-result').textContent =
+ `Difference: ${diffDays} day${diffDays !== 1 ? 's' : ''}`;
+ };
+
+ document.getElementById('calculate-date').addEventListener('click', calculateDate);
+
+ // Currency Calculator
+ const exchangeRates = {
+ USD: { EUR: 0.85, GBP: 0.73, JPY: 110.0 },
+ EUR: { USD: 1.18, GBP: 0.86, JPY: 129.5 },
+ GBP: { USD: 1.37, EUR: 1.16, JPY: 150.0 },
+ JPY: { USD: 0.0091, EUR: 0.0077, GBP: 0.0067 }
+ };
+
+ const calculateCurrency = () => {
+ const amount = parseFloat(document.getElementById('amount').value);
+ const fromCurrency = document.getElementById('from-currency').value;
+ const toCurrency = document.getElementById('to-currency').value;
+
+ if (isNaN(amount)) {
+ document.getElementById('currency-result').textContent = 'Please enter a valid amount';
+ return;
+ }
+
+ let result;
+ if (fromCurrency === toCurrency) {
+ result = amount;
+ } else {
+ result = amount * exchangeRates[fromCurrency][toCurrency];
+ }
+
+ document.getElementById('currency-result').textContent =
+ `${amount} ${fromCurrency} = ${result.toFixed(2)} ${toCurrency}`;
+ };
+
+ document.getElementById('calculate-currency').addEventListener('click', calculateCurrency);
+ });