Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS Sass Basics Write Smart and Efficient CSS with Sass Write a Sass Function

Finally, create a rule that targets an h1. Use the px-to-rem function to convert a font-size value of 60px to a value in

Finally, create a rule that targets an h1. Use the px-to-rem function to convert a font-size value of 60px to a value in rem units.

style.scss
$base-font-size: 16px;

// Write your function here
@function px-to-rem ($target, $context:$base-font-size) {
@return ($target / $context) * 1rem;
}

h1 {
font-size:px-to-rem (60px, rem);
}

4 Answers

Actually, Jeanne (above is correct). You don't need that rem parameter in the function because you're already multiplying by 1rem to get rem units. Here is the solution in an easy to read format.

$base-font-size: 16px;

// Write your function here
@function px-to-rem($target, $context: $base-font-size) {
  @return ($target / $context) * 1rem;
}

h1 {
  font-size: px-to-rem(60px);
}```

Note that there is no space between "px-to-rem" and the parentheses. The engine will reject this:
```h1 {
  font-size: px-to-rem (60px);
}```

THIS GUY HAS THE RIGHT ANSWER ^

Jeanne Bachmann
Jeanne Bachmann
765 Points

$base-font-size: 16px;

// Write your function here @function px-to-rem ($target, $context: $base-font-size) { @return ($target / $context) * 1rem; }

h1 { font-size: px-to-rem(60px); }

You just have to write "(60px)" and you must delete space between "px-to-rem" and "(60px);" Hope it's the right way :)

I think that i'm close, but dont know exactly what to do

// I think this is what you're looking for

h1 { font-size: px-to-rem(60px, 1rem); }

// The rem unit needs a value so just writing (60px, rem) like above doesn't give it the proper calculation. This should help though.

h1 { font-size: px-to-rem(60px); }```

is the correct answer, minus the three back ticks...