try
function find(id) { return document.getElementById(id) }
function calsPerDay( ) {
var age = parseFloat(find("age").value);
var weight = parseFloat(find("weight").value)
var bodyfat = parseFloat(find("bodyfat").value)
var result = 0
if (find("Sedentary").checked)
result = (370 + ((21.6 * ((weight / 2.20462) * (100 - bodyfat))) / 100)) * 1.2
else if (find("Lightly Active").checked)
result = (370 + ((21.6 * ((weight / 2.20462) * (100 - bodyfat))) / 100)) * 1.375
else if (find("Moderately Active").checked)
result = (370 + ((21.6 * ((weight / 2.20462) * (100 - bodyfat))) / 100)) * 1.55
else if (find("Extremely Active").checked)
result = (370 + ((21.6 * ((weight / 2.20462) * (100 - bodyfat))) / 100)) * 1.725
var calsperDay_Result = Math.round(result)
find("calsPerDay").innerHTML = calsperDay_Result;
return calsperDay_Result;
}
function myFunction() {
var calsPDay = calsPerDay();
var age = parseFloat(find("age").value)
var bodyfat = parseFloat(find("bodyfat").value)
var result = 0;
if (bodyfat > 18 && (age <= 30) && (find("female").checked))
result = (500);
else if (bodyfat < 18 && (age = 31) && (find("female").checked))
result = (2 + 2);
else
result = (20 + 1);
document.getElementById("macros").innerHTML = Math.round(result);
}
use
parseFloat() Function[
^] to convert string to a float value for mathematical calculation.