Categories
- Beauty & Style
- Computers & Technology
- Education & School
- Entertainment
- Environmental Issues
- Food & Dining
- FunAdvice Community
- Gaming & Games
- General Knowledge
- Health
- Home and Garden
- Jobs & Money
- Kids
- Love and Relationships
- Music
- Nutrition and Fitness
- Parents & Family
- Pets & Animals
- Politics
- Religion & Spirituality
- Science
- Shopping
- Sports
- Travel
- Writing & Literature
To explain a little bit more:
new_number = number.to_i + 1
Converts "number" which you converted to a string before with "gets.chomp.to_s" (you read the input from the terminal and converted it to a string so it can be appended to the other string that you are printing out with the other "puts" statement. Fine.
However, a short way to do all that is also:
number = gets.chomp.to_i + 1
puts ' A better number is ' + number.to_s




Can anyone help me with this ruby script?
Send me Fun Mail
I am very new to ruby and I was hoping someone could help me. In the following script I am asking the user their favorite number. I would then like to add a one to their favorite number and suggest the resultant number as a better favorite number.
puts 'What\'s your favorite number?'
number = gets.chomp.to_s
puts 'Your favorite number is '+number+'.'
If anyone could tell me how to this it would be great!