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 trialAndres Maza
3,640 PointsProblems with JS Octal Numbers
Hello i'm trying to solve the following problem
"Create a variable named "mevol" and assign the value 16 to it using an octal number literal.”
Now i've done the following:
var mevol = 016;
This gives me the following error: "Oops! You've set "mevol" to the decimal number 14 using the octal literal 016. Try setting it to decimal number 16 by adding 2 to your octal literal 016.”
I’ve tried using 0162, 01602, 016 + 02, but nothing goes through. I was wondering, what is the correct solution to the problem? Thank You!
4 Answers
Jeff Busch
19,287 Points16 decimal = 20 octal. I just Googled decimal to octal.
Andres Maza
3,640 PointsHuh, 020 worked. No idea how it did though lol.
Thanks!
James Barnett
39,199 Points- Convert decimal
16
to octal using a conversion calculator you'll get20
- Recall that in JavaScript octal numbers are represented with a leading
0
so that would make020
Michael Randall
Courses Plus Student 10,643 PointsOk, octal is interesting, but difficult to explain. In a 10 base numbering system, the 1 means we have one 10. In the 8 base or octal system, the 1 means we have one 8. So, to get the number 8 in octal javascript, I believe it is represented as 010. When we have 020, that means we have two 8s or 16.
So, what about the last column? In 10 base numbering, that column is the 1's column and it goes from 0-to-9. In octal, that is also a 1's column but it goes from 0-to-7 and then starts over. So if we wanted the number 18 in octal, I believe that would be represented by 022. Ok that was my best shot. Hope it helps someone.
Jason Mc Dermott
11,496 Pointsplease excuse my naivety but I wrestled with this question myself for a few minutes before finding the answer here, this is all very new to me but a good learning experience none the less. I see that the octal system can be straight forward when you get the hang of it, but i still don't get how decimal 16 converts to octal 20 if it jumps in two's shouldn't it be 18?? The explanation above my post looks to make sense, but if anyone else would like a stab at it any feed back would be appreciated.
Susan Murphy
522 PointsHi Jason! As Michael noted, "In octal, that is also a 1's column but it goes from 0-to-7 and then starts over". Might be easier to see it written out: Decimal: 1, 2,...,7, 8, 9, 10, 11, 12, 13, 14, 15, 16 Octal: 1, 2,...,7, 10, 11, 12, 13, 14, 15, 16, 17, 20