×

ruby · level 1 · unit 6 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Ask an array questions with , , and .

Arrays know some handy methods. .include? asks whether an item is in the array. Methods ending in ?, like .even?, always answer with true or false.

For arrays of numbers, .sum adds up every item, .max finds the biggest and .min finds the smallest. No loop needed.

Need something trickier, like every score over 5? Walk through with .each and check each item with an if. Add break when you only want the first match.

scores = [4, 9, 2, 7]
puts scores.include?(9)
puts scores.sum
puts scores.max
puts scores.min

include? is case-sensitive, so "Dog" and "dog" are different items.