App Academy

Ruby Intro to Programming "is valid name" exercise why my version not working correctly?

Hello there, I am new on App Academy taking open free course which started with Ruby. I am wondering for “is valid name” practice why my version of the code not working correctly I can’t find the problem. I would appreciate if some one can explain that.

Instructor’s original code as follows
def is_valid_name(str)
parts = str.split(" ")
if parts.length < 2
return false
end

parts.each do |part|
if !is_capitalized(part)
return false
end
end

return true
end

def is_capitalized(word)
if word[0] == word[0].upcase && word[1…-1] == word[1…-1].downcase
return true
else
return false
end
end

puts is_valid_name(“Kush Patel”) # => true
puts is_valid_name(“Daniel”) # => false
puts is_valid_name(“Robert Downey Jr”) # => true
puts is_valid_name(“ROBERT DOWNEY JR”) # => false

My version of the code as follows
def is_valid_name(str)
parts = str.split(" ")
if parts.length > 1
parts.each do |part|
if part[0] == part[0].upcase && part[1…-1] == part[1…-1].downcase
return true
else
return false
end
end
else
return false
end
end

puts is_valid_name(“Kush Patel”) # => true
puts is_valid_name(“Daniel”) # => false
puts is_valid_name(“Robert Downey Jr”) # => true
puts is_valid_name(“ROBERT DOWNEY JR”) # => false

I accept my version should give the same result as original code and it does for the given parameters as it is but when I change parameters like (“Kush patel”) from “Patel” or (“Robert downey Jr”) from “Downey” which I change the letter case for the 2nd parts (Last names) it doesn’t return correct result I can’t find the problem! I would appreciate if some one show me why.
Thank you in advance.
Matthew

<> I found the solution, corrected my version of the code as fallows

def is_valid_name(str)
parts = str.split(" ")

if parts.length < 2
  return false
end

parts.each do |part|
    if !((part[0] == part[0].upcase) && (part[1..-1] == part[1..-1].downcase))
      return false
    end
end
return true

end