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

CSS

I am having trouble in Sass with functions

Sass has me very confused. I have a simple code challenge that I can't figure out what I am doing wrong, and the video doesn't seem to cover it.

instructions: "Write a function, called 'double,' that multiplies its input by 2.

Seems simple enough, but I'm stuck!

I thought the Sass code would read:

@function($input * 2)

but that gets me the message, "Bummer. The function needs to take a parameter named '$input'"

In the video, the instructor says we have to have a @return? If so, what would it all look like?

Thanks for your help

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hey there! I've never used Sass, but a quick Google search tells me your code should look like this:

@function double($input){
  @return $input * 2
}

@function tells you it's a function, double is the name you're giving the function, the parentheses after the name are where you put any parameters - in this case $input, then you open and close curly braces. The code inside the braces is what your function does. And the @return is what your function will spit out!

This is very similar to the syntax in other programming languages.