0

Why does this code, the result is false ??

https://code.sololearn.com/cM8Qmnjc64jl/?ref=app

1st Feb 2021, 11:01 AM
Carbon dioxide
Carbon dioxide - avatar
9 ответов
+ 2
Because an integer type doesn't equal a string/character type.
1st Feb 2021, 11:03 AM
Slick
Slick - avatar
+ 2
Slick but in the code it's "==" not "===" which I am still confused about because "==" compares the value regardless of the data type tho while "===" compares the value and the data type. I'm confused as well on why 1 == '1' is false. or does Ruby do not have the "===" operator. UPDATE:- I was thinking of Javascript that is why. Sorry about that.
1st Feb 2021, 11:05 AM
aka :)
aka :) - avatar
+ 2
MrDevEzeoke All i know is when i switched '1' to 1 the output is True. Logically, that's the answer. Not sure about ruby equal signs, but they seem to follow the same rules as other languages. I could be wrong!
1st Feb 2021, 11:08 AM
Slick
Slick - avatar
+ 2
Where's the logic in the second sentence? 1 is definatley 1. But that don't mean 1 == '1'. Looking it up, all it says is that == is equal to, doesnt say anything about different data types. === is case equality and will check equality in whatever a "case" is. I still think it's the different data types
1st Feb 2021, 11:18 AM
Slick
Slick - avatar
+ 2
Oh... I see, because there is different data types... Thanks for the answer MrDevEzeoke 🌟αnurαg kumαr🌟 Slick ...
1st Feb 2021, 11:37 AM
Carbon dioxide
Carbon dioxide - avatar
+ 2
1 == '1' is false because 1 is int type and something which is written inside double or single quotes is called string . https://code.sololearn.com/cQ8Ak6rLvF9N/?ref=app
2nd Feb 2021, 1:22 PM
Abhiyantā
Abhiyantā - avatar
+ 1
1 is 1 That mean's 1 == '1' The question is "Why does this code, the result is false..."
1st Feb 2021, 11:11 AM
Carbon dioxide
Carbon dioxide - avatar
+ 1
Because any number which is not surrounded in quotes are numbers ex----->5 is a number and anything that is surrounded by quotes are characters ex------>'6' and "6" is a character That's why your Program: puts 1=='1'---->give false ; puts 1==1------->give true; Because both are same data types I think you have understood properly my friend Jeff's : )
1st Feb 2021, 11:18 AM
Anurag Kumar
Anurag Kumar - avatar
+ 1
Jeff's JK (HTML challenger and the coders 💻)🇮🇩 So overall, it's False because they are different data types.
1st Feb 2021, 11:21 AM
aka :)
aka :) - avatar