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
Tam Hartman
4,012 PointsCode Challenge: Creating Flexible Margins
Hey There, I'm working on the Creating Flexible Margins Code Challenge and I'm running into an issue with the second item. In the first item, the quiz asks you to convert the margins on the .cake from pixels to percentages using the .icing width as a target. Icing width (800px)/cake margin(10px) = 0.0125, or 1.25%. No problem.
The second item asks you to convert the filling margin to percentages using the .cake width as target. .cake width(640px)/.filling margin(10px) = 0.0156 or 1.56%. However, when I add that into my code it always comes back as incorrect. Am I missing something here or... what's going on?
Thanks! Tamasaur
10 Answers
James Barnett
39,199 PointsLet's look at the math ...
0.0156 * 640 = 9.984
In most cases the decimals on the end of pixels are just dropped. So you'd end up with a 9px margin instead of a 10px one.
In the real world it's a matter of how much percision you want, for me personally I use 3 decimal places when converting pixels to percentages.
Guil Hernandez
Treehouse TeacherHi Tam,
You're close. Hint: Just add the next two numbers in the decimal value –– don't round. It's important to include the full decimal value to make sure the margins are as accurate as possible.
Jeffrey Vierra
25,404 PointsI ran into the same issue...
natashalovesmith
19,360 PointsYes this just happened to me. Frustrated...I calculated 1.56% for the margin percentage.
natashalovesmith
19,360 PointsOK I get that but it was a code challenge. I used the conversion correctly and apparently got the right answer yet I can't finish the challenge because "my numbers are slightly off." And watched the video again to make sure I was doing it correctly.
Gareth Edwards
7,243 PointsPlease can someone give a detailed explanation of this question and provide all the maths. I'm finding the maths above pretty frustrating; Icing width (800px)/cake margin(10px) = 0.0125, or 1.25%. That does not make sense. I understand that 800/640 =1.25% and completed the first task but I could really do with some help to gain a better understanding of this. Many Thanks
Tam Hartman
4,012 PointsI tried what Guil said and it worked perfectly. Just use more of the decimal places and add the next two numbers instead of rounding.
Gareth Edwards
7,243 PointsI understand the first part, but I didn't use the calculation provided above does not make sense to me. If I calculate 800/10 it gives 80. I understand that 800/640=1.25 and for the second part 800/480=1.66 however I'd just like a more detailed explanation.
Thanks
Tam Hartman
4,012 PointsIt's the other way around. 10/800, not 800/10. 10/800=0.0125. :)
Gareth Edwards
7,243 PointsThanks for your help Tam.