Insert Word into String.. what is wrong


#1

----Question------------------
Insert the word “easy” into the end of the string "Ruby makes automation ". Hint: it
might be useful to utilize negative indexing here

—my Solution -----------------------

str = "Ruby makes automation "
puts str.insert(-1,“easy”)

-------------error--------------------------
Incorrect Response
Almost; remember that to insert text into a string, you can set the length portion of the index to 0

------please advice correct Answer---------


#2

Works for me:

 >> str = "Ruby makes automation "
 => "Ruby makes automation "
 >> str.insert(-1,"easy")
 => "Ruby makes automation easy"

However, I would have used the more idiomatic (and easier to understand)

 str += "easy"

Ronald


#3

“Ruby makes automation” << “easy”


#4

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