简体   繁体   English

我不知道我的编码有什么问题。 (javascript)

[英]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.

相关问题 不知道我的 IF 语句有什么问题(JAVASCRIPT) - Don't know what's wrong with my IF statement (JAVASCRIPT) 我没有弄明白我的JavaScript代码有什么问题 - I don't get what's wrong with my Javascript code 元素在我的代码中不会.fadeTo。 不知道怎么了JavaScript,JQuery,HTML - elements wont .fadeTo in my code. Don't know what's wrong JavaScript, JQuery, HTML 我不知道“渲染”有什么问题 - I don't know what's wrong with 'render' 我不知道联系表有什么问题 - I don't know what's wrong with contact form 看不到我的JavaScript语法有什么问题吗? - Don't see what's wrong with my javascript syntax? TypeError: undefined is not a function(靠近'...(0,_react.useCallBack)...')。 我不知道我的代码中的 usCallBack() function 有什么问题 - TypeError: undefined is not a function (near '...(0, _react.useCallBack)...'). I don't know what's wrong with the usCallBack() function in my code 我的Javascript不起作用。不知道它是函数,我是如何调用它,我使用的CSS或者是什么 - My Javascript doesn't work. Don't know if it's the Function, how I'm calling it, the CSS I used or what if/else 语句似乎在 Javascript 中不起作用,我不知道我做错了什么 - If/else statements just do not seem to be working in Javascript and i don't know what I am doing wrong 我的javascript输出与预期输出不匹配。 我不知道哪里出错了 - My javascript output does not match the expected output. I don't know where I went wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM