Area of Rectangle Calculator

Area of Rectangle Calculator

Input Parameters

Results

Area:
Perimeter:
Diagonal:
Aspect Ratio:
Show Diagram:

Calculation History

No calculations yet

`; printWindow.document.write(printContent); printWindow.document.close(); printWindow.print(); }function downloadPDF() { // Simple PDF generation using print functionality const originalTitle = document.title; document.title = 'Rectangle Calculator Results'; // Create a temporary print-friendly version const printArea = document.createElement('div'); printArea.innerHTML = `

Rectangle Calculator Results

Generated on ${new Date().toLocaleString()}

Area: ${document.getElementById('area-result').textContent}
Perimeter: ${document.getElementById('perimeter-result').textContent}
Diagonal: ${document.getElementById('diagonal-result').textContent}
Aspect Ratio: ${document.getElementById('ratio-result').textContent}
Formulas: Area = Length × Width; Diagonal = √(L²+W²); Perimeter = 2(L+W)
`; // For a real implementation, you'd use a PDF library like jsPDF showToast('Use your browser\'s Print > Save as PDF feature to download PDF'); document.title = originalTitle; }async function shareResults() { if (!navigator.share) { showToast('Web Share API not supported on this device'); return; } const results = { area: document.getElementById('area-result').textContent, perimeter: document.getElementById('perimeter-result').textContent, diagonal: document.getElementById('diagonal-result').textContent, ratio: document.getElementById('ratio-result').textContent }; const shareText = `Rectangle Calculator Results: Area: ${results.area} Perimeter: ${results.perimeter} Diagonal: ${results.diagonal} Aspect Ratio: ${results.ratio}Generated on ${new Date().toLocaleString()}`; try { await navigator.share({ title: 'Rectangle Calculator Results', text: shareText }); } catch (error) { if (error.name !== 'AbortError') { console.error('Error sharing:', error); showToast('Error sharing results'); } } }// Add keyboard shortcuts info document.addEventListener('keydown', function(e) { if (e.ctrlKey || e.metaKey) { switch(e.key) { case 'Enter': e.preventDefault(); calculate(); break; case 'r': e.preventDefault(); resetCalculator(); break; } } });