Learn to Program

Chapter 5

Mixing It Up


Baby name choices

I'm going to ask for two girl names and then spit them out in a sentence.

  1. #Baby Names

  2. puts 'If you were to have a baby girl, what would you name her?'

  3. gname1 = gets.chomp

  4. puts 'What is your second choice?'

  5. gname2 = gets.chomp

  6. puts 'So if you had a girl, you would name her '

  7. + gname1 + ' or ' + gname2 + '? Those are nice names.'

Result:

So if you had a girl, you would name her Jessica or Abigail? Those are nice names.

Favorite Number

Ask the user for a favorite number; subtract 1 from the number. Suggest that the new number is better then their favorite number because it is smaller and more compact.

  1. #Favorite number

  2. puts 'What is your favorite number?'

  3. favNumber = gets.chomp

  4. puts favNumber + ' is a good number. But ...'

  5. puts 'I think that ' + (favNumber.to_i - 1).to_s + ' is even better.'

  6. puts 'Don\'t you want a better, more compact favorite number?'

Result:

2 is a good number. Butt... I think that 1 is even better. Don't you want a better, more compact favorite number?