[英]I don't know what's wrong with my coding. (javascript)
function calculateBmr(){
var weight = prompt("Enter weight in pounds");
var height = prompt("Enter height in inches");
var age = prompt("Enter age");
var bmr = 655 + (4.35 * weight) + (4.7 * height) - (4.7 * age);
alert("Your BMR is" bmr " calories.");
}
calculateBmr();
What's wrong with my code? 我的代码有什么问题? It won't run.
它不会运行。
alert("Your BMR is" bmr " calories.");
应该
alert("Your BMR is" + bmr +" calories.");
Try: 尝试:
function calculateBmr(){
var weight = parseFloat(prompt("Enter weight in pounds"));
var height = parseFloat(prompt("Enter height in inches"));
var age = parseFloat(prompt("Enter age"));
var bmr = 655 + (4.35 * weight) + (4.7 * height) - (4.7 * age);
alert("Your BMR is " + bmr.toString() + " calories.");
}
calculateBmr();
The parseFloat
s will ensure that what the user enters is a number and +
ought to be used for string concatenation. parseFloat
可以确保用户输入的数字是数字,并且+
应该用于字符串连接。
Try this 尝试这个
alert("Your BMR is" +bmr+ " calories."); 警报(“您的BMR是” + bmr +“卡路里。”);
you have to use the operator + 您必须使用运算符+
+bmr+
+宝马+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.