+ 1
Pls can anyone explain it
MyNum = 42 # Trying to change the value produces a warning MyNum = 8
8 Antworten
+ 4
Interesting. I saw the first(Most popular) comment on that lesson and that guy is completely right.
Its value can be modified (it produces a warning not error!).
But it's a very common (recommended) pattern to begin "constant" variable names with a capital letter. For that reason it produces a warning.
I don't know much Ruby just making assumptions.
+ 3
AJ Anant Yes. But I was wrong.
+ 1
Can you show your code?
+ 1
thanks you all
+ 1
Anointing Ijejeme Did you get answer?
0
i didn’t get it i just use hint and ot filled in the answer
0
If you start the name of the variable with a capital letter, Ruby will understand it is a constant therefore it can't change value once defined.
Problem would be solved if you started the name of the variable with a miniscule like below:
___________________________
myNum = 42
# puts myNum - this outputs 42
# Trying to change the value produces a warning
myNum = 8
# puts myNum - this outputs 8 - confirms the value of the variable has been changed
____________________________