Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Ruby variables

Now that you have a name variable, create another variable called "favorite_food" with your favorite food. Bummer! We can't find the variable 'favorite_food'. PreviewRecheck work variable.rb

name = "My Name" name = "favorite_food"

whats wrong?

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

The variable name needs to be favorite_food, so it should look something like this:

favorite_food = "pizza"

so whats a variable in ruby? an =eaqule sing= ? like in PHP $ this is variable and in ruby = is variable right?

and i know maybe this question is weird or whatever but since you have 3k points on ruby , did it teach you alot about it?

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

I'm not sure how to explain this, since I don't know what your background in programming is. Please don't hate me if the below description sounds too basic or even childish.

Variable is basically a container that has a name and can store something. In Ruby it can store anything (in languages like C you need to declare what type of thing it will store - a number, a character, a string etc.). So to just create an empty variable you just write:

favorite_food

It now exists but does not have any content. To put content inside, you use the assignment operator =. So this puts a string "pizza" inside your variable:

favorite_food = "pizza"

You can later put something else inside using the same operator:

favorite_food = 34

So = is an assignment operator that lets you put things inside variables :).

aaaaaaa so that mean that a variable in ruby is basicaly anything that you write and with = you just asign it what it willl go like prints on screen or gets to prompt right? my programming experience is week coz i did only ike basics of PHP and a bit of JS basics but im going to learn Ruby and i will stick with it because i see that they have alot of nice videos and i need to get started so thats my desision and i hope its good.

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

Yes, you got it :). And good decision. Let me quote an article that I came across by accident some time ago:

"[t]he likelihood that PHP is being used is strongly anti-correlated with company quality."

You should also do free exercises on http://www.codecademy.com/ - this will reinforce your knowledge you get from Treehouse videos.

And yes, Treehouse taught me a lot, but videos are not enough - you always need to practice, code on your own, try things, fail, find out why you failed and try another thing.

O i hope that basic CSS and HTML are enough . Well ill do that , when i get throw my basics video i go and do it on codeacademy . Thank you . BDW stay warm in Poland :D

Shailesh Gor
Shailesh Gor
2,975 Points

Now that you have a name variable, create another variable called favorite_food with your favorite food.name ="Raj" puts = "hello!" puts name favorite _ food = 12 puts = "favorite food" puts favorite _ food