0
0
Kotlinprogramming~10 mins

If-else expression assignment in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
If-else Expression Assignment in Kotlin
📖 Scenario: You are creating a simple program to decide if a person is eligible to vote based on their age.
🎯 Goal: Build a Kotlin program that uses an if-else expression to assign a message about voting eligibility.
📋 What You'll Learn
Create an age variable with a specific value
Create a variable votingMessage that uses an if-else expression to assign the correct message
Use the exact messages: "Eligible to vote" and "Not eligible to vote"
Print the votingMessage variable
💡 Why This Matters
🌍 Real World
Deciding eligibility or status based on conditions is common in apps like voting systems, age verification, or access control.
💼 Career
Understanding if-else expressions is fundamental for writing clear and concise Kotlin code in many software development roles.
Progress0 / 4 steps
1
Create the age variable
Create an age variable of type Int and set it to 20.
Kotlin
Need a hint?

Use val age: Int = 20 to create the variable.

2
Create the votingMessage variable with if-else expression
Create a variable called votingMessage and assign it using an if-else expression that sets it to "Eligible to vote" if age is 18 or more, otherwise "Not eligible to vote".
Kotlin
Need a hint?

Use val votingMessage = if (age >= 18) "Eligible to vote" else "Not eligible to vote".

3
Use the if-else expression to assign the message
Make sure the votingMessage variable uses the if-else expression exactly as if (age >= 18) "Eligible to vote" else "Not eligible to vote".
Kotlin
Need a hint?

Check that the if-else expression is exactly as required.

4
Print the votingMessage
Write a println statement to print the votingMessage variable.
Kotlin
Need a hint?

Use println(votingMessage) to display the message.