mardi 29 mars 2016

JavaScript Beginner Syntax Errors

I wrote this program out in plain code but I don't know Javascript well enough to get all the syntax right. I am a beginning programming please help me with corrections to my code. It is currently not running at all. We are still going over loops and it's really giving me trouble. This is for a college class. (I know this isn't formatted properly that's why i'm asking for help)

function main(){
alert("Welcome to the program");
 var fatGrams;
 var calories;
 var percentage;
 function getFatGrams(fatGrams);
 function getCalories(calories);
 function caloriesPercentage; 
 function displayPercentage(percentage); 
}

function getFatGrams(fatGrams){ 
prompt("Enter the number of fat grams in your food item");
while fatGrams < 0{
  alert("Error, the fat grams cannot be less than 0.");
  prompt("Enter the new number of fat grams.");
}
return fatGrams
}

function getCalories(fatGrams,calories,getFatGrams){
prompt("Enter the number of calories in your food item.");
 while calories < 9 OR calories > fatGrams * 9{
  alert("Error, the calories cannot be less than 9 or exceed the fat    grams * 9");
 prompt("Enter the new number of calories");
}
return calories;
}

function caloriesPercentage(fatGrams,calories){

set percentage = (fatGrams * 9) / calories;
alert("The amount of calories that come from fat is, " percentage);
return percentage;
}

function displayPercentage(percentage){
if percentage < 0.3 then {
 alert("The food is low in fat.");
 else
end if 
}
}
main(); 
alert("End of program"); 

Aucun commentaire:

Enregistrer un commentaire