【问题标题】:Function that return true if all three parameters are strict unequal. JS [closed]如果所有三个参数都严格不相等,则返回 true 的函数。 JS [关闭]
【发布时间】:2021-06-02 01:38:28
【问题描述】:

我不知道为什么我的函数不起作用。 它应该像这样工作:

If 1 !== 2 and 1 !== 3 and 3 !== 2 
returns True
else
return False

我的函数不起作用并且总是返回 False idk 为什么

x = 1
z = 2
y = 3
function unequal(x,y,z) {
    if (x !== z || y !== z || x !== y) {
        console.log('True')
    }
    else {
        console.log('False')
    }
}
(unequal())

【问题讨论】:

  • ||等于或,所以替换||通过 &&
  • 仍然总是打印错误
  • 你没有向你的方法传递任何东西。试试不等(x,y,z)
  • x, yz 在你的函数中都是undefined
  • 因为你也需要把变量放在 unequal() 中

标签: javascript equals inequality


【解决方案1】:
x = 1
z = 2
y = 3
function unequal(x,y,z) {
    if (x !== z && y !== z && x !== y) {
        console.log('True')
    }
    else {
        console.log('False')
    }
}
(unequal(x, y, z))

x = 1
z = 2
y = 3
function unequal() {
    if (x !== z && y !== z && x !== y) {
        console.log('True')
    }
    else {
        console.log('False')
    }
}
(unequal())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    相关资源
    最近更新 更多