13.Being Pushy


#1

I put this:

   alphabet = ["a", "b", "c"]
   ["a", "b", "c"] << "d"

   caption = "A giraffe surrounded by "
   "A giraffe surrounded by " << "weezards!"

But it says,
"Oops, try again. It looks like your code doesn't add "d" to the end of ["a", "b", "c"]."
and it puts
"A giraffe surrounded by weezards!"

Why does it put only "A giraffe surrounded by weezards!" ?


#2

As far as I know you're supposed to push the values into the variables, not into new identical objects.


#3

But why does it only put

   "A giraffe surrounded by weezards!"

instead of

   ["a", "b", "c", "d"]
   "A giraffe surrounded by weezards!"

#4

Because it's not a real output, it's just ruby evaluating the last instruction and displaying what it evaluates to.

If you want to print something on the output yourself, use puts or print.


#5

I don't know why but it puts

     ["a", "b", "c", "d"]A giraffe surrounded by weezards!nil

#6

And it still says


      Oops, try again. It looks like your 
      code doesn't add "d" to the end of ["a", "b", "c"].

#7

Are you pushing the "d" to the variable or the anonymous array?


#8

i am pushing it to the array


#9

I put

     alphabet = ["a", "b", "c"]
     alphabet << ("d") # Update me!

     caption = "A giraffe surrounded by "
     caption << "weezards!" # Me, too!

and it worked


#10

Of course it worked, because you needed to push on the variables ^^. Good luck for the rest of the course.