Does jade syntax support switch statement?

I tried this in jade, served by express, but got an "unexpected id" as an error.

- switch(myvar) - case: "0" span First Case break - case: "2" span Second Case break - case: "3" span Third Case break - case: "4" span Fourth Case break 

I was curious what the syntax is for the switch statement, if any.

Update: jade, not expression.

+7
source share
1 answer

EDIT

This question seems to be about Jade.

But the answer is still yes :).

But it is called case :

From the docs

 case friends when 0 p you have no friends when 1 p you have a friend default p you have #{friends} friends 

Javascript has a switch statement.

 switch(variable){ case 1: // do something break; case 2: // do something else break; // and so forth default: // do something if nothing break; } 

Being that Express.js works in Node.js, which is just JavaScript - yes. Express has a switch because JavaScript has a switch . (Even coffeescript has a switch that "compiles" before the JavaScript switch .)

MDN Link: switch statement

Your syntax seems to be flawed - what are the "-" characters? You also lack : from the end of each case , and you are not break ing after each case, which means that the code for ALL cases will ALWAYS work regardless of the condition.

+18
source

All Articles