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 trialGoldSpec Digital
4,185 PointsFunctions using variables
Hi,
So in this example Guil uses the variables $a and $b - would these need to be defined beforehand as a variable?
I don't understand what the $a and $b are meant to represent, and how using variables can make using functions interchangeable?
Any help would be awesome!
1 Answer
richporter
16,727 PointsYou don't need to define the variables beforehand, they are for use within the function.
It is basically saying to the function, 'hey, when I call you later on, I should give you 2 values.. Which I want you to swap in place of $a and $b'.
@function divide($a, $b) {
@return ($a / $b);
}
/* which when we call it */
font-size: divide(50px, 100px);
/* is essentially doing this */
@function divide(50px, 100px) {
@return (50px / 100px);
}
/**/
font-size:0.5;
GoldSpec Digital
4,185 PointsGoldSpec Digital
4,185 PointsOh thanks, that makes sense!