Pls can anyone explain it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Pls can anyone explain it

MyNum = 42 # Trying to change the value produces a warning MyNum = 8

18th Mar 2020, 9:13 PM
Anointing Ijejeme
Anointing Ijejeme - avatar
8 Answers
+ 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.
18th Mar 2020, 9:35 PM
Kevin ★
+ 3
AJ Anant Yes. But I was wrong.
18th Mar 2020, 9:37 PM
Kevin ★
+ 1
Can you show your code?
18th Mar 2020, 9:18 PM
A͢J
A͢J - avatar
+ 1
thanks you all
18th Mar 2020, 9:20 PM
Anointing Ijejeme
Anointing Ijejeme - avatar
+ 1
Anointing Ijejeme Did you get answer?
18th Mar 2020, 9:35 PM
A͢J
A͢J - avatar
0
i didn’t get it i just use hint and ot filled in the answer
18th Mar 2020, 9:38 PM
Anointing Ijejeme
Anointing Ijejeme - avatar
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 ____________________________
20th Mar 2020, 8:17 PM
Daniel Leu
Daniel Leu - avatar