Complete the code to assign the maximum of two numbers to max using if as an expression.
val max = if (a > b) [1] else b
The if expression returns a if a is greater than b, otherwise b.
Complete the code to assign a message based on the number using if as an expression.
val message = if (num % 2 == 0) [1] else "Odd number"
The if expression returns "Even number" if num is divisible by 2, otherwise "Odd number".
Fix the error in the code by completing the if expression to return the correct value.
val result = if (score >= 50) [1] else "Fail"
The if expression must return a string value. "Pass" is the correct string to return when score is 50 or more.
Fill both blanks to create a variable that holds a description based on age using if as an expression.
val description = if (age [1] 18) [2] else "Adult"
The condition checks if age is less than 18. If true, it returns "Minor", otherwise "Adult".
Fill all three blanks to create a variable that returns a grade description based on score using if as an expression.
val grade = if (score [1] 90) [2] else if (score [3] 60) "Fail" else "Pass"
The first condition checks if score is 90 or more and returns "Excellent". The second condition checks if score is less than 60 and returns "Fail", otherwise "Pass".