-1
I’m right at the beginning of my studies with JS, so I got a little lost in this exercise.
I need to type check the single parameter of the 'check' function. When it is True, it returns False and vice versa, for booleans. When it is a Number returns its negation (e.g. 10, resume -10).
But when this parameter is false, it takes the value of a Number, in the case of 0 (and returns -0), when it is 1, it takes the value of a Boolean, in the case of True (and returns False).
I don’t understand why when the parameters are 0 or True, the function runs as expected.
function verifi(par){
if (par == (true || false)){
return !par
} else if((par >= 0) || (par <= 0)){
return par * (-1)
} else{
return "Não encontrado! O parâmetro é do tipo " + typeof par
}
}
console.log(verifi(0)) //retorna -0, assim como esperado
console.log(verifi(1)) // deveria retornar -1, porém retorna false
console.log(verifi(false)) // deveria retornar true, porém retorna -0
console.log(verifi(true)) //retorna false, assim como esperado
Your first if seems to be the problem
(true || false)
– Christian Beregula