Challenge: Absolute Value
Test yourself and implement what you have learned so far in this challenge.
We'll cover the following
Problem Statement
You need to create a function absolute
which computes the absolute value of a given number.
Input
The input of the function is a number x
of type Double
whose absolute value you want to compute.
Output
The output will be the absolute value of x
.
Sample Input
-5
Sample Output
5
Test Yourself
Write your code in the given area. Try the exercise by yourself first, but if you get stuck, the solution has been provided. Good luck!
def absolute(x: Double): Double = {// Write your code herereturn -1 // Remove this line after writing your code}
Let’s go over the solution review in the next lesson.