 Challenge: Conditionals and Logic
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 scoreis greater than or equal to 90
- "Good" if scoreis between 75 and 89
- "Average" if scoreis between 50 and 74
- "Poor" if scoreis 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
1234567891011121314fun 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 scorevariable.
- Complete the conditions in the if-else statements to check the value of score.
- Print the appropriate message based on the value of score.
1234567891011121314fun 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!
Tak for dine kommentarer!
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 5.26 Challenge: Conditionals and Logic
Challenge: Conditionals and Logic
Stryg for at vise menuen
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 scoreis greater than or equal to 90
- "Good" if scoreis between 75 and 89
- "Average" if scoreis between 50 and 74
- "Poor" if scoreis 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
1234567891011121314fun 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 scorevariable.
- Complete the conditions in the if-else statements to check the value of score.
- Print the appropriate message based on the value of score.
1234567891011121314fun 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!
Tak for dine kommentarer!