S
S
Sir0zha2019-11-10 18:18:25
Swift
Sir0zha, 2019-11-10 18:18:25

How can I convert a negative number to a positive number in a function?

You need to find the opposite number given. For example, there is 1, you need to find -1.
I tried with negate (it didn't work because I don't know how to use it correctly), I tried with if (but I don't understand what condition I should write). My code:
if number < 0 {
return number * -number Codewars
problem, initial conditions:
func opposite(number: Double) -> Double {
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Cherny, 2019-11-10
@Sir0zha

I don't understand what number = -number's wrong?
ornumber *= -1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question