SimonSays Titleize Question

Hi guys,

I am working on the Simon Says challenge in the RSPEC 1 file. For the titleize method, I was wondering why it is necessary to declare the “little words” variable in all caps.

ex. LITTLE_WORDS = [‘and’, ‘over’, ‘the’] vs. little_words = [‘and’, ‘over’, ‘the’]

It took me a while to figure out that the lowercase version does not work. I’m sure there is a simple explanation for this, I just want to understand it thoroughly so I do not make the same mistake in the future.

Thanks!

Hey JackieLiP,

Good catch on lower case not working!

When we CAPITALIZE a variable, its called a constant.

The main difference between local variables and constants is that constants can be accessed anywhere from within the file, while local variables can only be accessed from the block of code in which it was defined in.

So, if I have a file that has a constant defined on the first line of the file, I can access it from inside any class or method that is defined in the same file. On the other hand, if I have a file that has a local variable defined on the first line, and then I have a class or method, I won’t have access to that variable from inside.

Hope this helps :).

Mashu

Very helpful. Thanks!