javascript - JavaScript 应用条件和函数
问题描述
我必须根据 javascript 中的以下规则创建 IF 条件。如果可以请帮助:
- 主要数字之和应等于限制范围内其他数字之和
//First example
var a = 5; //asume a is sum of main numbers
var b = 10; // b is sum of other numbers
var limit = 11; //limit
if ((a==b) < limit) //something like this
alert("true");
else
alert("false");
//It should return false as a is not equal b but within limit but it is not working.
//Second example
var a = 15;
var b = 17;
var limit = 11;
if ((a==b) < limit)
alert("true");
else
alert("false");
//third example
var a = 15;
var b = 17;
var limit = 11;
if ((a==b) < limit)
alert("true");
else
alert("false");
如何在 JavaScript 中创建 if 条件,该条件将根据上述规则返回布尔值 true 或 false。我可以在这里使用一些内置的数学函数吗,比如 Math.abs 等。
解决方案
你可能想要的是这样的:
if ((a===b) && a < limit)
更新:正如评论中指出的那样, ifa== b
和a < limit
,b
必须是< limit
,所以不需要检查。
推荐阅读
- c# - 如何从字符串中解析出前三个单词?
- ruby-on-rails - 如何在不使用模型常量的情况下在路线中使用模型?
- android - 12 小时后安排作业,应用程序在后台运行。
- javascript - 如何使用 es6 'Class' 语法定义私有成员并在类本身中使用它
- firebase - “过去 30 分钟内的用户”计数不是预期的
- azure - Microsoft 图形 API:与附加的共享点和令牌一起使用时出现未经授权的错误
- java - 如何通过按钮单击在应用程序图标上设置通知编号?
- reactjs - 基于来自 redux 的另一个 api 响应传递数据
- html - 如何在 javascript 中访问 svg 元素的内部 html 并进行更改?
- webgl - 如何在 webgl 中设置 SharedArrayBuffer 类型的 bufferData?