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

Write a function, called double, that multiplies its input by 2.

I can't figure out step one to this 3 part. I don't really think I'm close with my answer but I've tried so many different variations, I am too confused at this point, can someone help me out?

$double: 10px;

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

15 Answers

I believe it is asking for a function called double, you are declaring a function called input then using a variable called double.

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

link The Sass Way

Thank you Adam, I knew I was over-complicating things.

No problem. Always ensure to re read the question ensure the task is fulfilled.

Try this: div { font-size: unquote(double(5) + "px"); }

This might help if you still need it :)

div { font-size: double(5px); }

It's not working :(

I can't figure out how to finish this:

Use the double function you just wrote to refactor this code: div { font-size: 5px * 2; }

and none of the stuff posted here work.

  • Got it. was a simple typographical error on my part.

unquote

Hey amrutabuge,

Your previous code was:

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

They are giving you this div:

div { font-size: 5px * 2;
}

So

font-size: 5px * 2; <----- This is the same as saying --> font-size= double(5px) since "double(5px)" is calling your function

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

and replacing ($input) for 5px.

Hope it helps. T.

Hey Dylan,

You should change 10px to 10 (without the px) You can only perform multiplication on numbers.

Thanks for the tip Craig. After removing the 'px' I am still getting an error "We need a function named 'double'."

I am struggling on my code form for this section, do you know what else is wrong with my answer?

Any advice for the Challenge Task 2 in the Sass Functions? Specifically, the challenge asks "Use the double function you just wrote to refactor this code: div { font-size: 5px * 2; }" Link http://teamtreehouse.com/library/sass-functions

.

Hey Dylan,

Now it's just a case of changing the name of the function to be called double. Try that. (I haven't used variables in CSS before, so there may be other syntax mistakes)

""" $number = 10;

@function double($number) {@return $number * 2;}

"""

Help! I am struggling with Task 2 as well.

"Use the double function you just wrote to refactor this code: div { font-size: 5px * 2; }"

Link: http://teamtreehouse.com/library/sass-functions

Has anybody found an answer to this problem?

Yes the first answer. Been up voted 5 times

Dang five times!

Did it work?

Yep I figured it out shortly after I posted :)

div{ font-size:double(5px) }

it is saying to use the double function and refactor the exisiting code div {font-size:5px *2;}

I wrote: div { font-size: unquote(double(5px));} and I passed the task correctly! Do you think guys that´s correct?? I think maybe it was a bug :D