Other Pages

Expand All
Slides

Input And Output

Input and Output

Terminal I/O

LAB: Hello, friend!

  1. Open hello.rb in your text editor
  2. Change it to contain the following code:

    puts "What is your name?"
    name = gets
    puts "Hello, " + name + "!"
    
  3. Save the file and switch back to the terminal

  4. Run the program using ruby hello.rb

  5. Type in your name and press the RETURN (or ENTER) key

What happens? Is this what you expected?

Yikes!

Breathe

Let's fix this

The newline character

Strip it

LAB: fixing Hello, Friend

LAB: Capitalization

LAB: Crazy Name

LAB: Full Name

CONGRATULATIONS!

You just wrote a program!

You are now officially a coder. HIGH FIVE!

Lab: Name Length

Back to Learn To Code

If you find something that could be improved, please make a pull request or drop us a note via GitHub Issues (no technical knowledge required).

Source: https://github.com/RailsBridge-CapeTown