+ 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)
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
+ 1
Thank you very much.
0
Still the same error is coming
0
I actually had used small later for array. It's a class name. Its first name should be capital. Thank you very much.