Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Deeper into Routing with Express The Response Object

Pug error "unexpected token else"

I get a weird error were pug doesn't recognize the else. The same code works in the video.

extends layout.pug

block content
    If name
        h2 Welcome fellow student #{name}!
    else
        form(action="/hello", method="post")
            label Please enter your name here
                input(type="text", name="username")
            button(type="submit") Submit
5|         h2 Welcome fellow student #{name}!
    6|         
  > 7|     else
-----------^
    8|         form(action="/hello", method="post")
    9|             label Please enter your name here
    10|                 input(type="text", name="username")

unexpected token "else"

1 Answer

I had the same issue, somehow it was hard to notice that capital I. Thank you!!