Ruby 1.4 Repeat for more input


#1

here is my code:

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

print "What's your last name?"
last_name = gets.chomp

print "What city do you live in?" 
city = gets.chomp

print "What state/province do you live in?"
state = gets.chomp

can someone please tell me what I'm doing wrong? It keeps saying error and asking if I declared a variable "last_name"


#2

Unable to reproduce error with direct paste in of above code. Are you entering data at the prompts?


#3

Yes I am, but it still won't take my code.


#4

I got it to where it doesn't say error anymore but the gear gif just spins. I had this problem the last three exercises I did.


#5

Are you running an app or a desktop version of CC?


#6

desktop version. Is there an app I can download?


#7

I don't know that for certain, though it's a good possibility. What all is included in Pro accounts is unknown to me. If there is an app, that's where I would look for it.

What browser/OS are you using?


#8

I am using google chrome


#9

Passed again in Chrome/Windows 7


#10

I have Windows 10 unfortunately


#11

I'm out of suggestions. These are some re-do considerations:

  • go back a lesson, submit and proceed
  • refresh the page
  • reset the lesson
  • clear cookies
  • clear CC from history
  • switch browser

The latter three are last resort, and I have never cleared cookies or history so don't know how or if that will help.


#12

Thank you I will take those under consideration.


#13

There is something wrong with the instructions on this one. Because once you correctly run the code it puts the first name out of order.

I got it done by trial and error. You need input the follow

first_name = gets.chomp
print "First Name"
last_name = gets.chomp
print "Last Name"
city = gets.chomp
print "City"
state = gets.chomp
print "State"


#14

This is what worked for me, after a zillion error messages and two or three offers to give up and get code. :stuck_out_tongue:

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

print "Last Name"
last_name=gets.chomp

print "City"
city=gets.chomp

print "What's the abbreviation for your State?"
state=gets.chomp

first_name.capitalize!
last_name.capitalize!
city.capitalize!
state.upcase!

puts "Your name is #{first_name} #{last_name} and you are from #{city}, #{state}."

At one point, the wheel stopped turning frantically and exercise got validated BUT the terminal did not really show the abbreviated state in .upcase!

Now it gives:
What’s your first name?pepa
Last Namepig
Cityparis
What’s the abbreviation for your State?ny
Your name is Pepa Pig and you are from Paris, NY.

OT: I would LOVE to add a space after the prompt but I’m learning to accept stuff, like I don’t yet know how to and also, was not required…

Hope that helps.


#15
print "What's your first name? "

print "Last Name: "

print "City: "

print "What's the abbreviation for your State? "

#16

Blockquote
print "What’s your first name? "
print "Last Name: "
print "City: "
print "What’s the abbreviation for your State? "

oh my, the endlessly spinning little green thingy and trial-erroring killed my brain. you add a space by adding a space, duh.

thanks! :slight_smile: