JK58 Posted August 25 Share Posted August 25 I'm planning to create a tool website using JavaScript, specifically a fireplace size calculator that I want to integrate into my existing WordPress site. Given that my website is built on WordPress, how can I effectively include the custom JavaScript code for the calculator? Are there any specific plugins or best practices I should follow to ensure smooth integration and functionality on my WordPress site? My Code is Below: HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Fireplace Size Calculator</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h1>Fireplace Size Calculator</h1> <p>Calculate the ideal fireplace size for your living area.</p> <form id="calculator-form"> <label for="width">Room Width (ft):</label> <input type="number" id="width" required> <label for="length">Room Length (ft):</label> <input type="number" id="length" required> <label for="height">Room Height (ft):</label> <input type="number" id="height" required> <button type="button" onclick="calculateSize()">Calculate</button> </form> <div id="result"></div> </div> <div class="footer"> <p>Created by Fireplace Adviser</p> </div> <script src="script.js"></script> </body> </html> CSS: body { font-family: Arial, sans-serif; background-color: #f5f5f5; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 300px; text-align: center; } h1 { margin-bottom: 20px; font-size: 24px; } label { display: block; margin-bottom: 5px; font-weight: bold; } input { width: 100%; padding: 8px; margin-bottom: 10px; border-radius: 4px; border: 1px solid #ccc; } button { background-color: #28a745; color: white; padding: 10px; border: none; border-radius: 4px; cursor: pointer; width: 100%; font-size: 16px; } button:hover { background-color: #218838; } #result { margin-top: 20px; font-size: 18px; font-weight: bold; } JavaScript: function calculateSize() { const width = parseFloat(document.getElementById('width').value); const length = parseFloat(document.getElementById('length').value); const height = parseFloat(document.getElementById('height').value); if (isNaN(width) || isNaN(length) || isNaN(height)) { document.getElementById('result').innerText = "Please enter valid dimensions."; return; } const roomVolume = width * length * height; const btuRequired = roomVolume * 20; // Example formula: 20 BTUs per cubic foot const fireplaceSize = btuRequired / 1000; // Convert to approximate size in inches document.getElementById('result').innerText = `Ideal Fireplace Size: ${fireplaceSize.toFixed(2)} inches`; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now