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 trialkaran Badhwar
Web Development Techdegree Graduate 18,135 Pointscolors array in loop
Why we did not attach #{colors} in the loop, as we passed the value how the pug will inject that array into the loop without #{} ?
1 Answer
Caleb Kemp
12,755 PointsIt's because of where it was placed in the code. In Javascript, if you were to write a string and wanted to put a variable inside of the string, you would probably do it like this.
let myVar = 5;
let string = 'I want to print this text and value ${myVar}';
However, if you wanted to use the variable in most parts of your code there would be no need to use the ${} notation, for example
let myVar = 5;
let secondVar = 3 + myVar;
As you can see the ${} notation was only necessary when the variable was inside a string. Well, a similar thing is happening in the .pug file. If you write text write after a tag (like p) that is expecting text, you must either use an equal sign with only the variable after it (like Andrew does on line 12 at 3:50), or you can use text and the variable if you use the #{} notation. However, all of this is probably a moot point since as you can here the #{} syntax is no longer supported. Support for that was dropped in version 2. I would provide an example of the new syntax, but it would be cruel to rob you of the joy of finding it for yourself in the documentation here. P.S. If you really need the examples, I would be happy to provide them although the documentation isn't to bad to navigate, hope that helps