Find the First Even Number in a List
📖 Scenario: Imagine you have a list of numbers from a game score sheet. You want to find the first even number to see when the player first scored an even point.
🎯 Goal: You will write a Ruby program that finds the first even number in a list using the find method.
📋 What You'll Learn
Create an array called
scores with the exact numbers: 3, 7, 8, 10, 15Create a variable called
is_even that holds a lambda to check if a number is evenUse the
find method with is_even to get the first even number from scoresPrint the found even number using
puts💡 Why This Matters
🌍 Real World
Finding the first item that meets a condition is common in data filtering, like finding the first available appointment or the first product in stock.
💼 Career
Many programming jobs require filtering lists or arrays to find specific data quickly, making this skill very useful.
Progress0 / 4 steps