Is there an error here?

Virtual Computer 17-1
In the example… why does output show “eric”=>668 instead of “eric”=>01234 ?

I can’t post the code because “new users can only mention 2 users in a post”… that’s stupid.

It seems that when you add a 0 before an integer, Ruby converts it to an octal base instead of a decimal one. 668 in decimal is 01234 in octal.

If you use 12345 instead you’ll see that it works normally.

2 Likes

@gaurangtandon: why not fix this as well :slight_smile:

Hi @sethappy :slightly_smiling:

Well, this isn’t some Codecademy exercise bug that I could fix or get it fixed from staff. This is by definition how Ruby numbers work. It supports numbers in four different bases:

  1. Decimal (base 10): Any number (12345)
  2. Octal (base 8): Numbers beginning with 0 (056 = 46)
  3. Hexadecimal (base 16): Numbers beginning with 0x (0x56 = 86)
  4. Binary (base 2): Numbers beginning with 0b (0b111 = 7)

Hope it helps! :smiley:

I know how Ruby numbers work, but this exercise is not the best moment to introduce octal numbers, don’t you think :slight_smile:

1 Like

Yes, I think you are right. You mean that this line in default code in the exercise:

my_machine = Machine.new("eric", 01234)

should be changed to:

my_machine = Machine.new("eric", 1234)

to avoid confusing users. Thanks for bringing this to my attention! Added to reported bugs list :smiley:

Yes. It’s in de details :slight_smile:

1 Like

I have tried to change the default code to:

my_machine = Machine.new("eric", 12345)
your_machine = Machine.new("you", 67890)

Please see if it works :slightly_smiling:

1 Like

Just came along this example and it’s still 01234.

Did you try resetting your code? I was just trying to edit, maybe the changes didn’t work :confused: I will see this again when I get more proper editing tools.

Quickly tried to reset the code and reload page but unfortunately it did not change Eric’s password.
Thanks for trying to fix it, you guys do an awesome job :slightly_smiling:

1 Like