Home Forums Chapter 5: The Jade Templating Language Better example for the `case` construct

This topic contains 0 replies, has 1 voice, and was last updated by  Yaapa 1 year, 7 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #117

    Yaapa
    Keymaster

    This example in the book:

    case hero.role
      when 'captain'
        div Yarr!
      when 'hacker'
        div w00t!
      default
        div Avast!
    

    might be too simple for some beginners to make sense. This one should give you more context:

    - for (var i in heroes) {
    
        hero = heroes[i]
    
        if hero.role == 'captain'
          .msg Aye Captain!
        else if hero.role == 'hacker' && hero.name != 'Napman'
          .msg Who goes there?
        else
          .msg Avast!
    - }
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.