CodeAcademy - Ruby - Putting the Form In The Formatter - Repeat for more input


#1

So I am going through CodeAcademy's Ruby Module and am on this section : Putting The Form In The Formatter - Repeat For More Input :

This is the prompt ---

first_name = gets.chomp("What is your first name?")
last_name = gets.chomp("What is your last name?")
city = gets.chomp("What city are you from?")
city = gets.chomp("What state are you from?")

When I Click Save and Submit code and enter my details :

Gengyang
Cai
Singapore
Singapore

I get this output :

Gengyang
Cai
Singapore
Singapore
"Singapore\n"

and this error message :

Oops, try again. Did you declare a variable called state ?

Any suggestions on how to fix it ?

Thanks alot ....


#2

Hi this part you have two variable city try to change one to state

city = gets.chomp("What city are you from?")
city = gets.chomp("What state are you from?")

then you should put all your prompt like that

print "What is your first name?"
first_name  = gets.chomp

#3

Doesn't seem to change anything --- it's exactly the same input and result as the original commands ....


#4

Can you post your new code and the error you get?

read this on how to format the code


#5

Ok ... it works now !

first_name = gets.chomp("What is your first name?")
last_name = gets.chomp("What is your last name?")
city = gets.chomp("What city are you from?")
state = gets.chomp("What state are you from?")
print "What is your first name?"
first_name = gets.chomp
print "What is your last name?"
last_name = gets.chomp
print "What is your city?"
city = gets.chomp
print "What is your state?"
state = gets.chomp

Gengyang
Cai
Singapore
Singapore
What is your first name? Gengyang
What is your last name? Cai
What is your city? Singapore
What is your state? Singapore
"Singapore"