Advertisement
karlakmkj

Simple program - get user input

Aug 25th, 2021
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.91 KB | None | 0 0
  1. =begin
  2. First Ruby program.
  3. puts will give new line while print do not. No parentheses or semicolons needed!
  4. =end
  5.  
  6. print "What's your first name? " #include a space at the end
  7. first_name = gets.chomp # gets means to get input from user, When getting input, Ruby automatically adds a blank line (or newline) after each bit of input; so chomp removes that extra line.
  8. first_name.capitalize! # use this method and include ! symbol to modify value contained within the variable without the need to reassign variable or assign to another variable
  9.  
  10. print "What's your last name? "
  11. last_name = gets.chomp
  12. last_name.capitalize!
  13.  
  14. print "What city are you from? "
  15. city = gets.chomp
  16. city.capitalize!
  17.  
  18. print "What state or province are you from? "
  19. state = gets.chomp
  20. state.upcase! # same way as above methods, in upcase or downcase
  21.  
  22. puts "Your name is #{first_name} #{last_name} and you're from #{city}, #{state}!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement