Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Conditionals and Logic | Kotlin Basics
Android Development with 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.

Main.kt

Main.kt

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!

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 8

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Kysy minulta kysymyksiä tästä aiheesta

Tiivistä tämä luku

Näytä käytännön esimerkkejä

Awesome!

Completion rate improved to 5.26

bookChallenge: Conditionals and Logic

Pyyhkäise näyttääksesi valikon

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.kt

Main.kt

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!

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 8
some-alt