Skip to content

Latest commit

 

History

History
35 lines (22 loc) · 1.11 KB

pattern_matching.md

File metadata and controls

35 lines (22 loc) · 1.11 KB

use the following data to answer the questions in this section

characters = [
  %{name: "Han",        type: :human,   rebel: true,    weight: 185},
  %{name: "Jabba",      type: :hutt,    rebel: false,   weight: 2200},
  %{name: "Chewie",     type: :wookie,  rebel: true,    weight: 350},
  %{name: "r2d2",       type: :droid,   rebel: true,    weight: 250},
  %{name: "Luke",       type: :human,   rebel: true,    weight: 140},
  %{name: "Boba Fett",  type: :human,   rebel: false,   weight: 175},
]

Note that there is more than one correct answer for all of these!

Exercise 1

  • In one line of code, set a variable called wookie_name to the name of the wookie character

Exercise 2

  • In one line of code, set a variable called 'weight' to how much Han weighs

Advanced (we haven't covered all of this yet, you'll likely need to read documentation)

Exercise 3

  • In one line of code, create a list of the names of the humans

Exercise 4

  • In one line of code, create a list of all the humans that weigh less than 180 lbs.

Answer