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 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);
}

5 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...

how is 60/16 =60 can someone explain