0
0
Kotlinprogramming~10 mins

Constant values with const val in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a constant integer named MAX_COUNT with value 100.

Kotlin
const val MAX_COUNT: Int = [1]
Drag options to blanks, or click blank then click option'
A"100"
B100
CMAX
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers, which makes them strings.
Trying to assign a variable name instead of a value.
2fill in blank
medium

Complete the code to declare a constant string named APP_NAME with value "MyApp".

Kotlin
const val APP_NAME: String = [1]
Drag options to blanks, or click blank then click option'
AMy_App
BMyApp
C'MyApp'
D"MyApp"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes for strings.
Not using quotes at all for string values.
3fill in blank
hard

Fix the error in the constant declaration for PI with value 3.14.

Kotlin
const val PI: Double = [1]
Drag options to blanks, or click blank then click option'
A3.14
B"3.14"
C3,14
Dpi
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma instead of a dot for decimals.
Putting the number inside quotes, making it a string.
4fill in blank
hard

Fill both blanks to declare two constants: MAX_SPEED as 120 and MIN_SPEED as 0.

Kotlin
const val MAX_SPEED: Int = [1]
const val MIN_SPEED: Int = [2]
Drag options to blanks, or click blank then click option'
A120
B100
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the values between MAX_SPEED and MIN_SPEED.
Using incorrect numbers like 100 or -1.
5fill in blank
hard

Fill all three blanks to declare constants: PI as 3.1415, E as 2.718, and GREETING as "Hello".

Kotlin
const val PI: Double = [1]
const val E: Double = [2]
const val GREETING: String = [3]
Drag options to blanks, or click blank then click option'
A3.1415
B2.718
C"Hello"
D"Hi"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings for numeric constants.
Using wrong string values for GREETING.