Contenido del Curso
Android Development with Kotlin
Android Development with Kotlin
Challenge: Conditionals and Logic
Let's practice using conditionals and logic in Kotlin!
In this task, you need to determine the type of a variable and write conditional statements to print different messages based on the variable's value. You will be provided with a variable score
. Depending on the value of score
, you will print:
- "Excellent" if
score
is greater than or equal to 90 - "Good" if
score
is between 75 and 89 - "Average" if
score
is between 50 and 74 - "Poor" if
score
is less than 50
First, declare the score
variable and assign it a value. Then, use conditional statements to print the appropriate message to the console.
Main
fun main() { var score: Int = ___ // Use if-else statements to print the appropriate message based on the score if (___) { println("Excellent") } else if (___) { println("Good") } else if (___) { println("Average") } else { println("Poor") } }
- Assign a value to the
score
variable. - Complete the conditions in the if-else statements to check the value of
score
. - Print the appropriate message based on the value of
score
.
fun main() { var score: Int = 85 // Use if-else statements to print the appropriate message based on the score if (score >= 90) { println("Excellent") } else if (score >= 75) { println("Good") } else if (score >= 50) { println("Average") } else { println("Poor") } }
Run the code to test different values of score
and see the different messages printed to the console!
¡Gracias por tus comentarios!