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

Muhammad Haris Khan
Muhammad Haris Khan
8,587 Points

Create a variable named "mevol" and assign the value 16 to it using an octal number literal. NOT WORKING

this is what i did

var mevol = 018;

why is it not working?

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title> JavaScript Foundations: Creating Numbers</title>
    <link rel="stylesheet" href="core.css">
    <script>
      // exponential notation
      //    1E6 === 1000000
      // 1.23E6 === 1230000

      // octal number literals
      //  06 ===  6
      //  07 ===  7 
      // 010 ===  8
      // 011 ===  9
      // 012 === 10
      var GermanyGDP = 3.4E12;
      var mevol = 018;    

    </script>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Creating Numbers: Part 2</h2>
    <script src="viewer.js"></script>
  </body>
</html>

1 Answer

Stone Preston
Stone Preston
42,016 Points

the octal value of 16 is 20, not 18.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title> JavaScript Foundations: Creating Numbers</title>
    <link rel="stylesheet" href="core.css">
    <script>
      // exponential notation
      //    1E6 === 1000000
      // 1.23E6 === 1230000

      // octal number literals
      //  06 ===  6
      //  07 ===  7 
      // 010 ===  8
      // 011 ===  9
      // 012 === 10
      var GermanyGDP = 3.4E12;
      var mevol = 020;    

    </script>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Creating Numbers: Part 2</h2>
    <script src="viewer.js"></script>
  </body>
</html>
Muhammad Haris Khan
Muhammad Haris Khan
8,587 Points

so after 017 it jumps to 020 to make it 16?

Stone Preston
Stone Preston
42,016 Points

yes. see this article on how you can convert from decimal to octal by hand. you might also want to read about the octal system and how it works