A little help please


#1

https://www.codecademy.com/courses/learn-ruby/lessons/putting-the-form-in-formatter/exercises/repeat-for-more-input?action=lesson_resume

I am on Ruby on the lesson “Repeat for more input” I typed what the Instructions told me and it told me I was
incorrect. Here is the code I typed: print what is your last name? last_name = gets.chomp print "Trojack" print" What's your city?" city = gets.chomp print "Minnieapoils print "What is your state? state = gets.chomp print "MN":confused:


#2

While I’m not sure the exact nature of the lesson, the syntax looks strange. I would expect it to look something like:

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

etc…

I only did part of the code to give you an example of what I would expect the syntax to be like. I think you get the idea.


#4

Edit: In the last 2 lessons the code was like this:print "What is your last name? last_name = gets.chomp "
so I expected it would be the same in this lesson


#5

This syntax is still off. The code is supposed to print the question and assign the answer to a variable. As you have listed it it will print to the screen (and it will not wait for input):

What is your last name? last_name = gets.chomp


In the code in your o.p. you have hard coded values. This program is about taking input. Everything in the quotes of a print statement is printed to the screen. The gets.chomp statement waits for input and assigns it to a variable. So, I would expect your code to look like this (though I recommend formatting it similar to my previous post):

print “What is your last name?” last_name = gets.chop


#6

Do you think there was a bug??


#7

Not a bug. Two issues…

  1. Your text is not in quotes in the first statement.
  2. One line, one action (unwritten rule). Your code appears to have two statements on one line (assuming the code portion is not in quotes).
puts "What is your last name?" last_name = gets.chomp
 > 
(repl):1: syntax error, unexpected tIDENTIFIER, expecting end-of-input
puts "What is your last name?" last_name = gets.chomp

 >

Now include a statement separator…

puts "What is your last name?"; last_name = gets.chomp

even better,

print "What is your last name? "; last_name = gets.chomp

and everthing works as expected. Still, this should occupy two lines for both readability, and the one line, one action rule.

puts "What is your last name?"
last_name = gets.chomp

or,

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

#8

its alright now I pressed the button “get code” and I did put doulbe Quotes in the leaaons code editor i made that other code in a hurry


#9

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