Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Conditionals and Logic | Kotlin Basics
Android Development with Kotlin
course content

Contenido del Curso

Android Development with Kotlin

Android Development with Kotlin

1. Kotlin Basics
2. Control Flow and Collections
3. Object-Oriented Programming in Kotlin

bookChallenge: 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.

kt

Main

copy
1234567891011121314
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") } }
  1. Assign a value to the score variable.
  2. Complete the conditions in the if-else statements to check the value of score.
  3. Print the appropriate message based on the value of score.
1234567891011121314
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") } }
copy

Run the code to test different values of score and see the different messages printed to the console!

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 8
some-alt