参数比较不胜任何工作

时间:2016-06-01 14:51:54

标签: javascript

一切正常 - 除了这一个if-else-statement之外的所有内容:

    else if ((day = 0 || day = 6) && (hour <= 19)) {
  greeting = "We wish you a nice weekend and a nice " +
  Weekdays[day] + ".";
  }

Firefox的错误消息:&#39; ReferenceError:左侧无效的分配&#39;

..它应该很容易,但到现在为止我还没找到问题。

感谢您的帮助,祝您度过愉快的一天!

1 个答案:

答案 0 :(得分:4)

使用==进行比较(value)和=进行比较。

所以在你的情况下,它应该是:

 ...
 else if ((day == 0 || day == 6) && (hour <= 19)) {
   greeting = "We wish you a nice weekend and a nice " +
   Weekdays[day] + ".";
 }
 ...

如果您需要同时按typevalue进行比较,则应使用===

简而言之:

var a = 10; // assigns value 10 to variable `a`

"1"==1      // true => Since == compares by value

"1"===1     // false => Since === compares by both type and value. In this case although value is 1, both are of different types (string and integer)