Giter Site home page Giter Site logo

kwk-l1-user-input-mini-lab-kwk-students-l1-nyc-080618's Introduction

User Input Mini App

Now that we know about gets-ing and puts-ing, let's build a simple input/output app. The main objective is to create an application that takes in user input, does something with that input, and then prints out an output.

Gets

The first thing we need to do is take in user input with the gets method. Remember, when an executed Ruby program hits the method gets, the program is going to pause and wait for the user to enter text into the terminal.

The way gets takes in input is important to remember. First, it always takes in input as strings. If a user enters 10, then gets interprets that as "10", not as an integer. The second thing to remember is that gets also takes in the newline character. When a user types in their input and then hits the enter button, gets keeps track of the input plus the line break. If we were going to NYC, your variable storing the input looks like this:

city = "nyc
"

See how the string doesn't end after the letter 'c', but actually jumps to the next line? That's the newline character that gets kept track of because of the user pressing the enter key after typing nyc. We don't want our string to include that newline character, so we have to add the chomp method to gets to remove that. chomp does exactly what it sounds like, it chomps off the return carriage by default. So, we'll use gets.chomp.

The Challenge: A Visit to your hometown

You're going to build an application to plan a tourist's visit to your hometown. You are going to need to create a new Ruby file by entering touch trip.rb into your terminal. Open trip.rb with your editor to start writing your program.

You'll want to ask the user where they would like to stay, what sites they want to visit, what food they want to eat, and how many nights they want to stay. For each question, you'll take in input from the user and store each piece in a variable. The tests will guide you through to make sure you've asked the tourist the right questions.

Once you have that input stored, you'll want to use string methods (like upcase, downcase, captialize, etc) to put the input in a proper format. You can always take a look at the Ruby documentation here to learn more about string methods you can use.

Your final output should use string interpolation to output the data in a full summary of their NYC itinerary.

Remember, you can execute your code by typing ruby trip.rb in terminal from inside the directory of this lab. When you're ready to check against the tests, run learn.

KWK-L1 User Input Mini App

kwk-l1-user-input-mini-lab-kwk-students-l1-nyc-080618's People

Contributors

sammarcus avatar danielseehausen avatar jordanbudi avatar aviflombaum avatar cheyenne2528 avatar dfenjves avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.