10. What function of --> .upcase?


#1

I don't have any error, of course just click Save & Submit!!.
Just wondering why there have '.upcase ' command after 'string[0]'. Since we do 'capitalize command' before ("ryan") and ("jane"). OR I miss something before....

by the way, after I put-out '.upcase' after string[0]' also make it CORRECT!.

this is my code after remove ".upcase"

# method that capitalizes a word
def capitalize(string) 
  puts "#{string[0]}#{string[1..-1]}"
end

capitalize("ryan") # prints "Ryan"
capitalize("jane") # prints "Jane"

# block that capitalizes each string in the array
["ryan", "jane"].each {|string| puts "#{string[0]}#{string[1..-1]}"} # prints "Ryan", then "Jane"

thank you, :slight_smile:


#2

Our program overwrites the native capitalize method so it is no longer on the table. This program must perform the equivalent action, though, else it doesn't meet our requirements.

string[0].upcase

will capitalize the first letter of the string. All the remaining characters are left as is.

The fact that your code passes regardless is simply a weakness in the SCT. Just because we pass does not mean we have the correct code (in some instances). This will vary from author to author. The onus is still upon ourselves to verify that our code is what is expected and does with it is expected to do.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.