+ 1

Error in array

a = ["cow","cat","rat","Tiger","man","birds","fish"] i=0 while i < a.size temp << a[i].capitalize break if temp[i] = "Rat" i+=1 end p Could you please tell me why this error comes? Error: undefined local variable or method `temp' for main:Object (NameError)

4th Dec 2018, 2:00 PM
Anand Raja
Anand Raja - avatar
5 ответов
+ 2
a = ["cow","cat","rat","Tiger","man","birds","fish"] i=0 temp = Array.new # you forgot to implicitly declared temp variable while i < a.size temp << a[i].capitalize break if temp[i] == "Rat" # "=" operator used for assignment you should use "==" operator for equality test i+=1 end p temp
4th Dec 2018, 3:18 PM
MO ELomari
MO ELomari - avatar
+ 1
Thank you very much.
9th Dec 2018, 5:20 PM
Anand Raja
Anand Raja - avatar
0
Still the same error is coming
8th Dec 2018, 6:21 PM
Anand Raja
Anand Raja - avatar
8th Dec 2018, 7:20 PM
MO ELomari
MO ELomari - avatar
0
I actually had used small later for array. It's a class name. Its first name should be capital. Thank you very much.
9th Dec 2018, 5:22 PM
Anand Raja
Anand Raja - avatar