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
Trevor Wood
17,828 PointsCode Challenge: Creating Numbers: Part 2 Question
It's not accepting any of the answers I give it. Anybody else solve this one?
<!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 = 34E11;
var mevol = 018;
var mevol = 0171;
var mevol = 012 + 06; /* This one was 16 but still didn't accept*/
</script>
</head>
<body>
<h1>JavaScript Foundations</h1>
<h2>Creating Numbers: Part 2</h2>
<script src="viewer.js"></script>
</body>
</html>
1 Answer
Gary Mann
8,639 PointsIn our normal decimal system, the last digit of our number is the 1's column and the second to last digit is the 10's column and so forth. So for example, in decimal:
16 = (1 x 10) + (6 x 1)
453 = (4 x 100) + (5 x 10) + (3 x 1)
That was easy, right? On to octal (base-8) numeral system:
We'll only use 8 digits; we'll use digits 0 through 7. We have the 1's column for numbers 0 through 7. Then the second to last digit in our number will be the 8's column.
I'll use a leading zero since that's the signal in JavaScript that we might be using octal.
octal number 010 = decimal (1 x 8) + (0 x 1) = decimal number 8
011 = (1 x 8) + (1 x 1) = decimal 9
017 = (1 x 8) + (7 x 1) = 15
We only use digits 0 through 7, so:
020 = (2 x 8) + (0 x 1) = 16. Yay!!
var mevol = 020;
What's the biggest number we could represent with 2 digits?
077 = (7 x 8) + (7 x 1) = 63
0100 = (1 x 64) + (0 x 8) + (0 x 1) = 64
Now that we understand that, I have no idea if we'll ever use it. In the meantime, I guess we won't lead our numbers in JavaScript with zero's.
Trevor Wood
17,828 PointsTrevor Wood
17,828 PointsThanks for explaining this to me. I understand it now, but I can't see myself using this feature anytime soon hah.
anyway I see now why 018 doesn't work and 020 does. basically 7 is the last number you can use.