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 trialMegan Weber
28,554 PointsSass for loop error
I'm trying to use a for loop to append values to my list variable, ra
.
This is my code:
$ra: ();
@for $i from 1 through 10 {
append($ra, $i, comma);
}
I'm getting this error:
Error: expected "{".
append($ra, $i, comma);
style.scss 3:24 root stylesheet
2 Answers
Rich Donnellan
Treehouse Moderator 27,708 PointsWhat are you trying to accomplish? The @for
loop expects some kind of CSS output. It seems like you're just trying to programmatically store the values 1-10
in a variable.
Megan Weber
28,554 PointsI just needed to assign the value returned by append()
to $ra
.
Megan Weber
28,554 PointsMegan Weber
28,554 PointsYes. I wanted to store different shadows in the list & after the loop set an element's box-shadow property to the list. I got the same error when I tried that, so I thought I should simplify the code until I get the loop working.
Rich Donnellan
Treehouse Moderator 27,708 PointsRich Donnellan
Treehouse Moderator 27,708 PointsGotcha! Can you link me to a snapshot (e.g. Workspace, Codepen, Sassmeister, etc) of your full code? I can try to help you work this out.
This blog post might be of help: https://hugogiraudel.com/2013/07/15/understanding-sass-lists/
Megan Weber
28,554 PointsMegan Weber
28,554 PointsAfter reading the article, I tried assigning the value returned by
append()
to$ra
, & it worked! Thanks for your help :)Rich Donnellan
Treehouse Moderator 27,708 PointsRich Donnellan
Treehouse Moderator 27,708 PointsAwesome! Can you post as an answer what worked on the off chance it might help someone else here?