Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Girls in Tech - Hour of Code - 8/12/15

Avatar for Nick Dowse Nick Dowse
December 08, 2015
47

Girls in Tech - Hour of Code - 8/12/15

Avatar for Nick Dowse

Nick Dowse

December 08, 2015

Transcript

  1. Girls in Tech | Hour of Code In Partnership with

    New York Code + Design Academy in Amsterdam 1 Girls in Tech | Hour of Code
  2. Why learn to program? • Learn how to think logically

    • Stay one step ahead of "the machines" • Build anything you can imagine! 2 Girls in Tech | Hour of Code
  3. What is Ruby? • Written by Yukihiro "Matz" Matsumoto in

    the mid 1990s • "I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language."' - Matz • Known for the Ruby on Rails web development framework 3 Girls in Tech | Hour of Code
  4. Before we get started • Ruby code is written in

    a text editor • It is run from the command line • Download Sublime Text from http://www.sublimetext.com/3 4 Girls in Tech | Hour of Code
  5. Exercise: Working with Ruby • Open terminal.app and type cd

    ~/Desktop • Try creating a new file called test.rb • Inside the file, put the most basic Ruby program: puts "Hello World" • In your terminal run the program by typing ruby test.rb 5 Girls in Tech | Hour of Code
  6. Variables To declare a variable in Ruby, use this syntax:

    my_var = "Fifteen" my_number = 100.3 6 Girls in Tech | Hour of Code
  7. Data types in Ruby Ruby has a couple of different

    data types • Integers (Fixnum) • A number without a decimal • 11, 2000, 42, 0, -1 • Strings (String) • A line of text • "Jon", "12", "Nuclear washing cereal machine" 7 Girls in Tech | Hour of Code
  8. Data types in Ruby • Booleans (TrueClass, FalseClass) • literally

    true or false • true, false 8 Girls in Tech | Hour of Code
  9. Data types in Ruby • Arrays (Array) • A collection

    of values • [5,4,3, "omega", 15.9, "cappa"] • When assigned to variables, can be accessed with brackets a = [5,4,3, "omega", 15.9, "cappa"] a[0] > 5 9 Girls in Tech | Hour of Code
  10. Gathering data from a user If you're running your Ruby

    program from the command line, you can use gets to have the user type in some input: puts "What is your name?" name = gets puts "Your name is" puts name 10 Girls in Tech | Hour of Code
  11. Conditions A condition in Ruby is a test for something

    that evaluates to the boolean true or false 2 == 2 > true "Hello" == "Hey" > false 11 Girls in Tech | Hour of Code
  12. Logic • A logical statement evaluates a number of conditions

    and executes code based on their truthiness • Think of it as two paths diverging in a wood, if one condition is true, follow the left path, if false, follow the right path 12 Girls in Tech | Hour of Code
  13. The if statement The if statement allows us to run

    code only if a certain test evaluates to true if 5 > 10 puts "You'll never see this returned because 5 is not greater than 10" end if 5 < 10 puts "But you'll definitely see this" end 13 Girls in Tech | Hour of Code
  14. The else statement The else statement runs only if the

    statement in the if statement is false if 5 < 10 puts "You'll never see this because 5 is not greater than 10" else puts "You will see this though, since 5 < 10 evaluates to false" end 14 Girls in Tech | Hour of Code
  15. Final Challenge Construct a simple game of hangman where the

    user can guess a 3- letter word • Start with a sample word • Next, get user input • Compare this input with the sample word • Not sure what to do? Ask a TA or write some pseudocode! 15 Girls in Tech | Hour of Code