Day 3: Intro to Conditional Statements

  • + 0 comments

    Kotlin

    fun isWeird(n: Int) : String {
        val isOdd = n%2 != 0
        
        if (isOdd) {
                return "Weird"
        }
        
        if (n > 20) {
            return "Not Weird"
        }
        
        if (n in 2..5) {
            return "Not Weird"
        }
        
        if (n in 6..20) {
            return "Weird"
        }
        
        return "Not Weird"
    }