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

JavaScript JavaScript Foundations Numbers Creating Numbers: Part 2

Octal literal Question

The challenge question is "Create a variable named "mevol" and assign the value 16 to it using an octal number literal." <script> // exponential notation // 1E6 === 1000000 // 1.23E6 === 1230000

  // octal number literals
  //  06 ===  6
  //  07 ===  7 
  // 010 ===  8
  // 011 ===  9
  // 012 === 10
  var GermanyGDP = 34E11;
  var mevol = ;



</script>

5 Answers

Sreng Hong
Sreng Hong
15,083 Points

As you can see:

  // octal number literals
  //  06 ===  6
  //  07 ===  7 
  // 010 ===  8
  // 011 ===  9
  // 012 === 10

So what do you think that which number in octal is equal number 16 in decimal?

To give you a hint: 012 === 10 so we add 6 then it should be 018===16. It's right in decimal but octal is wrong, because in octal there only have number from 0 to 7.

Herb Bresnan
Herb Bresnan
10,658 Points

Gary,

If you are still confused, this may help. When figuring an octal literal, don't look at it as a number. Look at each individual value in terms of what position it holds.
For example, in Base 10, using the value of 128, each individual value has its own position.

The 1 is in the "hundreds" position; the 2 is in the "tens" position; and the 8 is in the "ones" position.

You have 1 "one hundred" ; 2 "tens", and 8 "ones."

(1*100) + (2*10) + (8*1) = 128

Right to left in Base 10, the position increases by a multiple of 10 .

Right to left in Base 8, the position increases by a multiple of 8.

Using the same example, 128, each individual value still has its own position. From right to left: "ones" position, " eights" position and the "sixty-fours" position.


Converting 128 to octal:

  • You need "2" sixty-fours
  • You need "0" eights
  • You need "0" ones The octal of 128 = 200

Converting 16 to octal:

  • You need "0" sixty-fours
  • You need "2" eights
  • You need "0" ones The octal for 16 = 020

Remember: No value can exceed the base

In base 8 the values are 0-7. Not exceeding 7. In base 10 the values are 0-9. Not exceeding 9.

Hope I did not confuse you more!! Good Luck.

So I put 027 and it says I'm wrong. 0 being 7, 2 making it 9, and then 7 making it 16. This is how I'm seeing it. I understand it cant go past 7 and 017 would give me 13. So what am I doing wrong

If you ever use octal numbers with JavaScript I'll eat my hat.

var mevol = 020;
Sreng Hong
Sreng Hong
15,083 Points

You see this:

  //  07 ===  7 
  // 010 ===  8

So after 017, it should turn to 020. I just give you the answer, please understand it as well. Good luck.