Coffescript切换时

时间:2015-07-22 16:52:04

标签: javascript coffeescript dashing

我的咖啡如下:

level = switch
      when 0 <= value <= 1 then 0
      when 1 < value <= 2 then 1
      when 2 < value <= 3 then 2
      when 3 < value <= 4 then 3
      when 4 < value <= 5 then 4
      else 6

为什么我会:

  

未捕获错误:ExecJS :: ProgramError:[stdin]:15:4:错误:意外   当1 <1时值&lt; = 2然后1

这很好用:

 when value <= cool then 0
      when value >= warm then 4
      else 
        bucketSize = (warm - cool) / 3 # Total # of colours in middle
        Math.ceil (value - cool) / bucketSize

这也有效:

 level = switch
      when value <= 1 then 0
      when value <= 4 then 4
      else 5

直到我添加 当值<= 2然后1

1 个答案:

答案 0 :(得分:0)

这完全是关于缩进的。

level = switch
      when 0 <= value < 1 then 0
      when 1 <= value < 2 then 1
      when 2 <= value < 3 then 2
      when 3 <= value < 4 then 3
      when 4 <= value <= 5 then 4
      else 5

我保留了代码:http://www.coffeelint.org/

然后检查缩进。