Function Challenge Basics
Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 16 of 93.
Some challenges give you a function to complete. The tests supply its inputs and check the value it returns. You do not write main or read console input in these tasks.
fun echoLabel(label: String): String {
return label
}Here fun declares a function named echoLabel. Inside the parentheses, label: String declares an input parameter. The : String after the parentheses declares the result type. Calling echoLabel("East") passes the argument "East" and produces that string.
return sends a value back to the caller and ends that function call. It does not print the value. Keep the supplied function name, parameter names and types, and return type; replace the unfinished body with your calculation. A later chapter teaches you to design and call your own functions.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorAugmented AssignmentComparison OperatorsRecap - Simple Math7Basic IO
Println FunctionString TemplatesReadLine InputType ConversionRecap - Years Until RetirementRecap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesNamed ArgumentsDefault ValuesSingle Expression FunctionsRecap - Sigma FunctionRecap - Validation Function2Variables
Val vs VarType InferenceNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Logical Operators Part 3Ternary With If ExpressionRecap - Simple Logic8Bill Split Calculator
Welcome MessageGetting Input3Nullability
What Is Null SafetyNullable TypesSafe Call OperatorElvis OperatorFunction Challenge BasicsNot Null AssertionRecap - Safe Access6Decision Making
If StatementIf - ElseIf As An ExpressionWhen ExpressionWhen With RangesRecap - Simple Calculator9Loops
For LoopWhile LoopDo-While LoopBreakContinueRanges In LoopsNested LoopRecap - FactorialRecap - Dynamic InputPractice on your own: Kotlin playground