One foot equals exactly 0.3048 meters. Convert feet to meters by multiplying by 0.3048; convert meters to feet by dividing by 0.3048.
const meters = feet * 0.3048;
const feet = meters / 0.3048;
Choose a conversion.
// Feet to meters
meters = feet * 0.3048;
// Meters to feet
feet = meters / 0.3048;
function feetToMeters(feet) {
return feet * 0.3048;
}
function metersToFeet(meters) {
return meters / 0.3048;
}
Form values should be checked before calculation. An empty field should not silently become zero.
function readFiniteNumber(raw) {
if (raw.trim() === "") return null;
const value = Number(raw);
return Number.isFinite(value) ? value : null;
}See numeric input validation for more comparison examples.
Keep the full numeric result for later calculations and format only when presenting it. toFixed() returns a string.
const result = feetToMeters(6.25);
console.log(result); // full Number
console.log(result.toFixed(2)); // formatted string
Each button reads the same input and chooses one conversion direction. Event listeners keep JavaScript out of inline HTML attributes, and textContent safely writes the result.
Continue with inches to centimeters and numeric validation.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.