Weight Calculator Density: Calculate Mass from Volume and Density
Easily determine the weight (mass) of an object using its known volume and density. This essential tool helps in various fields, from science and engineering to everyday material estimations.
Density Weight Calculator
Enter the density of the substance (e.g., kg/m³, g/cm³).
Enter the volume the substance occupies (e.g., m³, cm³). Ensure units match density.
Calculation Results
—
Weight Unit: —
Density Unit: —
Volume Unit: —
Formula: Weight = Density × Volume
Weight vs. Volume at Constant Density
This chart illustrates how the calculated weight changes with varying volumes, assuming a fixed density.
Density and Common Material Weights (Example)
Material
Density (kg/m³)
Volume (m³)
Calculated Weight (kg)
Example calculations for common materials. Units must be consistent.
{primary_keyword}
The weight calculator density is a specialized tool designed to compute the mass (commonly referred to as weight in everyday language) of an object or substance when its density and volume are known. It operates on a fundamental principle of physics: mass is a direct product of how much space an object occupies (volume) and how much matter is packed into that space (density). This calculator simplifies complex calculations, making it accessible to a wide range of users, from students learning about physical science to professionals in fields requiring precise material measurements.
Who Should Use a Weight Calculator Density?
This tool is invaluable for:
Students and Educators: For learning and teaching fundamental physics concepts related to mass, volume, and density.
Engineers and Designers: To estimate the weight of components, structures, or materials for design and structural integrity checks.
Material Scientists: For verifying material properties and performing calculations in experiments.
Logistics and Shipping Professionals: To estimate the weight of goods based on their volume and material type.
Hobbyists and DIY Enthusiasts: When working with materials like resins, metals, or woods for projects, understanding weight is crucial for stability and material cost.
Chefs and Food Scientists: For calculating the weight of ingredients based on their volume and density (e.g., flour, sugar, liquids).
Common Misconceptions about Density and Weight
Weight vs. Mass: While often used interchangeably, mass is the amount of matter, and weight is the force of gravity on that mass. This calculator computes mass.
Density is Constant: For a given substance under specific conditions (temperature and pressure), density is usually constant. However, slight variations can occur, and different substances have vastly different densities.
Heavier means Denser: An object can be heavy because it's large (large volume) even if its density is low (like a balloon), while a small object with high density (like a lead pellet) can be surprisingly heavy for its size.
{primary_keyword} Formula and Mathematical Explanation
The relationship between weight (mass), density, and volume is a cornerstone of physics. The core formula is derived from the definition of density itself.
The Fundamental Formula
Density ($\rho$) is defined as mass ($m$) per unit volume ($V$):
$\rho = \frac{m}{V}$
To find the mass (weight) when density and volume are known, we simply rearrange this formula:
$m = \rho \times V$
This is the equation our weight calculator density tool uses. You input the density and the volume, and it multiplies them together to output the calculated mass.
Step-by-Step Derivation
Start with the definition of density: $\rho = \frac{m}{V}$.
Our goal is to isolate 'm' (mass).
Multiply both sides of the equation by 'V': $\rho \times V = \frac{m}{V} \times V$.
The 'V' on the right side cancels out, leaving: $\rho \times V = m$.
Thus, the mass (weight) is the product of density and volume.
Variable Explanations
Understanding the variables involved is crucial for accurate calculations:
Variable
Meaning
Unit (Examples)
Typical Range (Examples)
$\rho$ (Density)
Mass per unit volume of a substance. It indicates how tightly packed the matter is.
The amount of three-dimensional space an object occupies.
m³, cm³, ft³, L
Highly variable, from microscopic to vast.
$m$ (Mass/Weight)
The quantity of matter in an object. This calculator outputs mass.
kg, g, lb, tonne
Depends on density and volume.
Key variables and their units used in the density weight calculation.
Practical Examples (Real-World Use Cases)
Let's explore how the weight calculator density is used in practical scenarios:
Example 1: Calculating the Weight of a Steel Block
An engineer needs to determine the weight of a solid steel block to be used in a machine's construction. They know the dimensions of the block and the density of steel.
Given:
Density of Steel ($\rho$): 7850 kg/m³
Volume of Block ($V$): 0.2 m³ (This could be calculated from dimensions like 1m x 0.5m x 0.4m)
Result: The tank holds 50,000 kg of water. This helps in understanding the structural load on the tank and the capacity of pumps.
How to Use This Weight Calculator Density
Our weight calculator density tool is designed for simplicity and efficiency. Follow these steps to get your results:
Step-by-Step Instructions
Identify Your Inputs: You need two key pieces of information: the density of the material you are working with and the volume it occupies.
Ensure Consistent Units: This is the most critical step! The units for density and volume must be compatible. For example, if density is in kilograms per cubic meter (kg/m³), then volume must be in cubic meters (m³). If density is in grams per cubic centimeter (g/cm³), volume must be in cubic centimeters (cm³). Our calculator will display the input units for clarity.
Enter Density: Type the numerical value for the material's density into the "Density of Material" input field.
Enter Volume: Type the numerical value for the object's volume into the "Volume of Object" input field.
Click "Calculate Weight": Press the button to see the computed mass.
How to Read Results
Primary Result: The largest, most prominent number displayed is the calculated mass (weight) of your object. The unit will be displayed next to it, derived from the input units (e.g., kg if density was in kg/m³ and volume in m³).
Intermediate Values: The calculator also shows the specific units for density and volume used in the calculation, reinforcing unit consistency.
Formula Explanation: A reminder of the simple formula used: Weight = Density × Volume.
Decision-Making Guidance
The results from this weight calculator density can inform various decisions:
Material Selection: Compare the weights of different materials with the same volume to choose the lightest or heaviest option as needed.
Structural Load: Determine if a structure or container can support the weight of the material it will hold.
Shipping Costs: Estimate shipping weights for materials, which often influence pricing.
Material Ordering: Ensure you are ordering the correct amount of material, understanding its mass implications.
Key Factors That Affect Weight Calculator Density Results
While the core calculation is straightforward ($m = \rho \times V$), several real-world factors can influence the accuracy and interpretation of results from a weight calculator density:
Unit Consistency: As mentioned, using mismatched units (e.g., density in g/cm³ and volume in m³) will yield a mathematically correct but physically meaningless result. Always double-check and convert if necessary.
Temperature and Pressure: The density of most substances, especially gases and liquids, changes with temperature and pressure. For highly precise calculations, ensure you are using density values specific to the operating conditions. For solids, the effect is often negligible unless undergoing extreme thermal expansion or compression.
Material Purity and Composition: The stated density is usually for a pure substance or a standard alloy. Impurities, different alloys, or mixtures (like concrete, which has aggregate, cement, and water) will have different densities.
Phase of Matter: A substance's density varies significantly between solid, liquid, and gaseous states. Ensure you are using the density corresponding to the substance's current phase.
Volume Measurement Accuracy: The precision of your volume measurement directly impacts the calculated weight. Small errors in measuring dimensions (length, width, height, radius) can lead to larger errors in calculated volume, especially for complex shapes.
Porosity and Inclusions: Some materials are porous (like sponges or certain ceramics), meaning they contain small voids that are filled with air or another substance. The bulk density accounts for this, but the volume of the solid material itself is different from the bulk volume. Similarly, materials might contain inclusions (e.g., trapped air bubbles in plastic) that affect overall density.
Accounting for Container Weight: If you are calculating the weight of a substance within a container, remember that the calculator only provides the weight of the substance itself. The total weight would be the substance's weight plus the container's weight.
Frequently Asked Questions (FAQ)
What is the difference between weight and mass?
Mass is the amount of matter in an object, measured in kilograms (kg) or grams (g). Weight is the force of gravity acting on that mass, typically measured in Newtons (N) or pounds (lb) in common usage. Our calculator outputs mass, which is often colloquially referred to as weight.
Can I use this calculator for liquids?
Yes, absolutely. As long as you know the density of the liquid (e.g., water, oil, mercury) and its volume, the calculator will accurately determine its mass. Ensure your units are consistent.
What if I have density in g/cm³ and volume in m³?
You must convert one of the units to match the other. A common conversion is 1 g/cm³ = 1000 kg/m³. So, if density is 1 g/cm³, enter 1000 in the density field if your volume is in m³. Or convert m³ to cm³ if your density is in g/cm³.
Does temperature affect the density of solids?
Generally, the effect of temperature on the density of solids is minimal compared to liquids and gases. However, for highly precise scientific or engineering applications, thermal expansion can slightly decrease density as temperature increases, and vice versa.
What is a typical density for common materials?
Densities vary widely. For example, water is about 1000 kg/m³, aluminum is about 2700 kg/m³, iron/steel is around 7850 kg/m³, and lead is about 11340 kg/m³. Always refer to reliable sources for specific material densities.
How do I find the volume of an irregular object?
For irregular solid objects, you can use the water displacement method. Measure the volume of water in a container, submerge the object, and measure the new water level. The difference is the object's volume. For liquids, measure directly using calibrated containers.
Can this calculator be used for gases?
Yes, but with a crucial caveat: gas density is highly sensitive to temperature and pressure. Ensure you use density values corresponding to the exact conditions under which the gas exists. Standard atmospheric pressure and room temperature are often assumed if not specified.
What units should I use for the output weight?
The output unit depends on the input units. If you use kg/m³ for density and m³ for volume, the output will be in kg. If you use g/cm³ for density and cm³ for volume, the output will be in grams. The calculator attempts to infer and display this, but user consistency is key.
Related Tools and Internal Resources
Volume CalculatorCalculate the volume of various geometric shapes, essential for using this density calculator.
Units Conversion ToolA comprehensive tool to convert between various units of length, area, volume, and mass.
var densityInput = document.getElementById('density');
var volumeInput = document.getElementById('volume');
var primaryResultDisplay = document.getElementById('primary-result');
var massUnitDisplay = document.getElementById('calculatedMassUnit');
var densityUnitDisplay = document.getElementById('densityUnitDisplay');
var volumeUnitDisplay = document.getElementById('volumeUnitDisplay');
var densityError = document.getElementById('densityError');
var volumeError = document.getElementById('volumeError');
var chartCanvas = document.getElementById('weightVolumeChart');
var ctx = chartCanvas.getContext('2d');
var weightVolumeChartInstance = null;
var defaultDensity = 1000; // kg/m³ (water)
var defaultVolume = 1; // m³
function validateInput(value, inputElement, errorElement, fieldName, minValue = 0, maxValue = Infinity) {
var error = false;
if (value === null || value === ") {
errorElement.textContent = fieldName + ' cannot be empty.';
errorElement.style.display = 'block';
inputElement.closest('.input-group').classList.add('error');
error = true;
} else {
var numValue = parseFloat(value);
if (isNaN(numValue)) {
errorElement.textContent = fieldName + ' must be a valid number.';
errorElement.style.display = 'block';
inputElement.closest('.input-group').classList.add('error');
error = true;
} else if (numValue maxValue) {
errorElement.textContent = fieldName + ' is out of a reasonable range.';
errorElement.style.display = 'block';
inputElement.closest('.input-group').classList.add('error');
error = true;
} else {
errorElement.textContent = ";
errorElement.style.display = 'none';
inputElement.closest('.input-group').classList.remove('error');
}
}
return error;
}
function calculateWeight() {
var density = parseFloat(densityInput.value);
var volume = parseFloat(volumeInput.value);
var densityErrorFlag = validateInput(densityInput.value, densityInput, densityError, 'Density', 0, 1000000); // Max density: e.g. Osmium ~22600 kg/m³
var volumeErrorFlag = validateInput(volumeInput.value, volumeInput, volumeError, 'Volume', 0, 1000000000); // Max volume: e.g. large industrial tank
if (densityErrorFlag || volumeErrorFlag) {
primaryResultDisplay.textContent = '–';
massUnitDisplay.textContent = 'Weight Unit: –';
densityUnitDisplay.textContent = 'Density Unit: –';
volumeUnitDisplay.textContent = 'Volume Unit: –';
updateChart([]);
clearMaterialTable();
return;
}
var calculatedWeight = density * volume;
var weightUnit = 'Units Mismatch'; // Default if units cannot be inferred
var densityUnit = 'Unknown';
var volumeUnit = 'Unknown';
// Attempt to infer units. This is simplified, real-world would need explicit unit selection.
// Assuming common pairs for demonstration.
if (densityInput.value && volumeInput.value) {
// Let's assume kg/m³ and m³ as primary for calculation and display
// If user enters 1000 for density and 0.5 for volume, we infer kg/m³ and m³
// and output kg.
densityUnit = 'kg/m³ (Assumed)';
volumeUnit = 'm³ (Assumed)';
weightUnit = 'kg (Assumed)';
if (densityUnitDisplay) densityUnitDisplay.textContent = 'Density Unit: ' + densityUnit;
if (volumeUnitDisplay) volumeUnitDisplay.textContent = 'Volume Unit: ' + volumeUnit;
}
primaryResultDisplay.textContent = calculatedWeight.toFixed(4);
massUnitDisplay.textContent = 'Weight Unit: ' + weightUnit;
// Update chart data
var chartData = generateChartData(density);
updateChart(chartData);
// Update material table data
populateMaterialTable(density);
}
function generateChartData(fixedDensity) {
var dataPoints = [];
var volumes = [0.1, 0.5, 1.0, 2.0, 5.0, 10.0]; // Example volumes
for (var i = 0; i d.x.toFixed(1)), // Volumes
datasets: [
{
label: 'Weight (kg)',
data: chartData.map(d => d.y),
borderColor: 'rgb(0, 74, 153)',
backgroundColor: 'rgba(0, 74, 153, 0.1)',
tension: 0.1,
fill: true,
pointRadius: 5,
pointHoverRadius: 7
},
// Add a point for the current calculation
{
label: 'Current Calculation',
data: [{x: currentVolume, y: primaryCalcWeight}],
borderColor: 'rgb(40, 167, 69)',
backgroundColor: 'rgba(40, 167, 69, 0.5)',
tension: 0,
fill: false,
pointRadius: 7,
pointHoverRadius: 9,
showLine: false // Don't draw a line for a single point
}
]
},
options: {
responsive: true,
maintainAspectRatio: true,
scales: {
x: {
title: {
display: true,
text: 'Volume (m³ – Assumed)'
}
},
y: {
title: {
display: true,
text: 'Weight (kg – Assumed)'
},
beginAtZero: true
}
},
plugins: {
tooltip: {
callbacks: {
label: function(context) {
var label = context.dataset.label || ";
if (label) {
label += ': ';
}
if (context.parsed.y !== null) {
label += context.parsed.y.toFixed(2) + ' kg';
}
return label;
}
}
}
}
}
});
}
function populateMaterialTable(currentDensity) {
var materials = [
{ name: 'Water', density: 1000 },
{ name: 'Aluminum', density: 2700 },
{ name: 'Steel', density: 7850 },
{ name: 'Lead', density: 11340 },
{ name: 'Pine Wood', density: 500 }
];
var tableBody = document.getElementById('materialTableBody');
clearMaterialTable();
var baseVolume = 0.1; // Use a consistent base volume for comparison
materials.forEach(function(material) {
var weight = material.density * baseVolume;
var row = tableBody.insertRow();
row.innerHTML = `
${material.name}
${material.density.toLocaleString()} kg/m³
${baseVolume.toLocaleString()} m³
${weight.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})} kg
`;
});
// Add a row for the current user input if values are valid
var currentUserDensity = parseFloat(densityInput.value);
var currentUserVolume = parseFloat(volumeInput.value);
if (!isNaN(currentUserDensity) && !isNaN(currentUserVolume) && currentUserDensity > 0 && currentUserVolume > 0) {
var currentUserWeight = currentUserDensity * currentUserVolume;
var row = tableBody.insertRow();
row.style.backgroundColor = '#e0f7fa'; // Highlight user input
row.innerHTML = `
${currentUserWeight.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})} kg
`;
}
}
function clearMaterialTable() {
var tableBody = document.getElementById('materialTableBody');
while (tableBody.firstChild) {
tableBody.removeChild(tableBody.firstChild);
}
}
function resetCalculator() {
densityInput.value = defaultDensity;
volumeInput.value = defaultVolume;
densityError.textContent = ";
densityError.style.display = 'none';
volumeError.textContent = ";
volumeError.style.display = 'none';
densityInput.closest('.input-group').classList.remove('error');
volumeInput.closest('.input-group').classList.remove('error');
calculateWeight(); // Recalculate with default values
}
function copyResults() {
var primaryResult = primaryResultDisplay.textContent;
var massUnit = massUnitDisplay.textContent;
var densityUnitInfo = densityUnitDisplay.textContent;
var volumeUnitInfo = volumeUnitDisplay.textContent;
var resultsText = "— Density Weight Calculation Results —\n\n";
resultsText += "Weight (Mass): " + primaryResult + "\n";
resultsText += massUnit + "\n";
resultsText += densityUnitInfo + "\n";
resultsText += volumeUnitInfo + "\n\n";
resultsText += "Formula Used: Weight = Density × Volume\n\n";
resultsText += "Key Assumptions:\n";
resultsText += "- Input units are consistent (e.g., kg/m³ for density and m³ for volume).\n";
resultsText += "- Material density is constant under operating conditions.\n\n";
resultsText += "Chart Data (Example Weights vs. Volume):\n";
if (weightVolumeChartInstance && weightVolumeChartInstance.data.datasets.length > 0) {
var chartDataPoints = weightVolumeChartInstance.data.datasets[0].data;
var chartLabels = weightVolumeChartInstance.data.labels;
for (var i = 0; i < chartDataPoints.length; i++) {
resultsText += `- Volume: ${chartLabels[i]} ${chartLabels[i] === 'm³' ? '' : 'm³'}, Weight: ${chartDataPoints[i]} kg\n`;
}
} else {
resultsText += "Chart data not available.\n";
}
resultsText += "\nMaterial Table Examples:\n";
var tableBody = document.getElementById('materialTableBody');
for (var i = 0; i ${row.cells[3].textContent}\n`;
}
}
var textarea = document.createElement('textarea');
textarea.value = resultsText;
textarea.style.position = 'fixed';
textarea.style.left = '-9999px';
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand('copy');
alert('Results copied to clipboard!');
} catch (err) {
console.error('Failed to copy results: ', err);
alert('Failed to copy results. Please copy manually.');
}
document.body.removeChild(textarea);
}
// Add event listeners for input validation on blur
densityInput.addEventListener('blur', function() {
var density = parseFloat(this.value);
validateInput(this.value, this, densityError, 'Density', 0, 1000000);
calculateWeight(); // Recalculate on blur
});
volumeInput.addEventListener('blur', function() {
var volume = parseFloat(this.value);
validateInput(this.value, this, volumeError, 'Volume', 0, 1000000000);
calculateWeight(); // Recalculate on blur
});
// Add event listeners for input validation on input (real-time feedback)
densityInput.addEventListener('input', function() {
var density = parseFloat(this.value);
validateInput(this.value, this, densityError, 'Density', 0, 1000000);
});
volumeInput.addEventListener('input', function() {
var volume = parseFloat(this.value);
validateInput(this.value, this, volumeError, 'Volume', 0, 1000000000);
});
// Initialize calculator and chart on page load
document.addEventListener('DOMContentLoaded', function() {
// Check if Chart.js is loaded (it's not, so we need to define it or use a dummy)
// For this example, assuming a global Chart object exists (as it would if included via CDN)
// If running standalone without Chart.js, the canvas part would fail.
// For a truly standalone solution, SVG or custom canvas drawing would be needed.
// Since the prompt requires pure JS/HTML/CSS, and native canvas API is allowed, we'll proceed.
// However, the actual charting library Chart.js is NOT native.
// Re-implementing basic chart drawing logic using native canvas API for strictness.
// Let's try to draw a simple line graph using native canvas API as Chart.js is external.
// This is a simplified native drawing for demonstration.
// The prompt allows native canvas, not necessarily a library.
// We'll skip the Chart.js library and draw manually for strict compliance.
// This requires a complete re-write of updateChart to use ctx.lineTo, ctx.stroke etc.
// For simplicity and to demonstrate the JS logic, I will keep the Chart.js structure
// and assume it's *available* in the environment, as complex charting with pure
// canvas API is extensive. If Chart.js is truly forbidden, this section needs a rewrite.
// Given the constraints (no external libraries), the Chart.js part MUST be replaced.
// I will comment out the Chart.js dependency and provide a placeholder for native drawing.
// For now, I'll proceed as if Chart.js is somehow implicitly available for the structure.
// *** IMPORTANT: If Chart.js library is strictly forbidden, the updateChart function needs to be fully rewritten using ctx.beginPath(), ctx.moveTo(), ctx.lineTo(), ctx.stroke() etc. ***
// Placeholder for native canvas drawing logic if Chart.js is disallowed.
// The current `updateChart` function uses `new Chart(…)`, which is from Chart.js.
// This needs to be replaced by direct canvas API calls.
// Simplified native canvas drawing logic:
function drawNativeChart(chartData, currentVolume, primaryCalcWeight) {
ctx.clearRect(0, 0, chartCanvas.width, chartCanvas.height);
var padding = 40;
var plotWidth = chartCanvas.width – 2 * padding;
var plotHeight = chartCanvas.height – 2 * padding;
if (chartData.length === 0) return;
// Find max Y value for scaling
var maxY = 0;
chartData.forEach(function(d) { if (d.y > maxY) maxY = d.y; });
if (primaryCalcWeight > maxY) maxY = primaryCalcWeight;
if (maxY === 0) maxY = 1; // Avoid division by zero
// Draw axes
ctx.strokeStyle = '#ccc';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(padding, padding); // Top left
ctx.lineTo(padding, chartCanvas.height – padding); // Bottom left
ctx.lineTo(chartCanvas.width – padding, chartCanvas.height – padding); // Bottom right
ctx.stroke();
// Draw labels and ticks (simplified)
ctx.fillStyle = '#666′;
ctx.font = '12px Segoe UI';
ctx.textAlign = 'center';
ctx.fillText('Volume', chartCanvas.width / 2, chartCanvas.height – padding / 2);
ctx.save();
ctx.translate(padding / 2, chartCanvas.height / 2);
ctx.rotate(-Math.PI / 2);
ctx.fillText('Weight', 0, 0);
ctx.restore();
// Draw data points and lines
ctx.strokeStyle = 'rgb(0, 74, 153)';
ctx.lineWidth = 2;
ctx.fillStyle = 'rgba(0, 74, 153, 0.1)';
var scaleX = plotWidth / (chartData[chartData.length – 1].x);
var scaleY = plotHeight / maxY;
ctx.beginPath();
chartData.forEach(function(d, index) {
var x = padding + d.x * scaleX;
var y = chartCanvas.height – padding – d.y * scaleY;
if (index === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
});
ctx.lineTo(padding + chartData[chartData.length – 1].x * scaleX, chartCanvas.height – padding); // Close shape visually
ctx.stroke();
ctx.fill(); // Fill the area under the line
// Draw current calculation point
ctx.fillStyle = 'rgb(40, 167, 69)';
ctx.strokeStyle = 'darkgreen';
ctx.lineWidth = 1;
var currentX = padding + currentVolume * scaleX;
var currentY = chartCanvas.height – padding – primaryCalcWeight * scaleY;
ctx.beginPath();
ctx.arc(currentX, currentY, 7, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
// Add point labels (simplified)
ctx.fillStyle = '#333';
ctx.textAlign = 'left';
ctx.fillText(`${currentVolume.toFixed(1)} vol`, currentX + 10, currentY – 10);
ctx.fillText(`${primaryCalcWeight.toFixed(2)} wt`, currentX + 10, currentY + 15);
}
// Replace the Chart.js based updateChart with the native one
window.updateChart = function(chartData) {
var currentDensityVal = parseFloat(densityInput.value) || defaultDensity;
var currentVolumeVal = parseFloat(volumeInput.value) || defaultVolume;
var primaryCalcWeightVal = currentDensityVal * currentVolumeVal;
// Ensure chartData is in a format suitable for drawNativeChart if it's different from the one used by Chart.js
// For this example, assume chartData is an array of {x: volume, y: weight} objects.
drawNativeChart(chartData, currentVolumeVal, primaryCalcWeightVal);
};
// Initial setup
resetCalculator();
// Need to call updateChart after resetCalculator has set initial values.
// The resetCalculator calls calculateWeight which in turn calls updateChart.
// This should be fine.
});
// FAQ toggles
var faqItems = document.querySelectorAll('.faq-item h4');
faqItems.forEach(function(item) {
item.addEventListener('click', function() {
var faqContent = this.nextElementSibling;
var faqItem = this.parentElement;
faqItem.classList.toggle('active');
if (faqItem.classList.contains('active')) {
faqContent.style.display = 'block';
} else {
faqContent.style.display = 'none';
}
});
});