0
0
Kotlinprogramming~15 mins

Range operator (..) and in operator in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Range Operator (..) and in Operator in Kotlin
📖 Scenario: You are organizing a small event and want to check if guests' ages fall within a certain age range for eligibility.
🎯 Goal: Build a Kotlin program that uses the range operator .. to create an age range and the in operator to check if a guest's age is within that range.
📋 What You'll Learn
Create an integer variable called guestAge with the value 25
Create a range called eligibleAgeRange from 18 to 30 using the .. operator
Use an if statement with the in operator to check if guestAge is in eligibleAgeRange
Print "Guest is eligible" if the age is in range, otherwise print "Guest is not eligible"
💡 Why This Matters
🌍 Real World
Checking if a person's age or a number falls within a valid range is common in forms, games, and eligibility checks.
💼 Career
Understanding ranges and membership tests is useful for data validation, filtering, and controlling program logic in many software development roles.
Progress0 / 4 steps
1
Create the guest age variable
Create an integer variable called guestAge and set it to 25.
Kotlin
Need a hint?

Use val guestAge = 25 to create the variable.

2
Create the eligible age range
Create a range called eligibleAgeRange from 18 to 30 using the .. operator.
Kotlin
Need a hint?

Use val eligibleAgeRange = 18..30 to create the range.

3
Check if guest age is in the eligible range
Use an if statement with the in operator to check if guestAge is in eligibleAgeRange. Inside the if, write println("Guest is eligible"). In the else block, write println("Guest is not eligible").
Kotlin
Need a hint?

Use if (guestAge in eligibleAgeRange) to check the range.

4
Print the eligibility result
Run the program to print the eligibility message based on the guest's age.
Kotlin
Need a hint?

Check the console output for the eligibility message.