You should use quotes to make this comparison. I also suggest you change the name of the function parameter to day:
function hojeSeJoga (dia){
if (dia=="domingo"){
console.log("Hoje é dia de futebol")
return true;
}else{
console.log("Hoje não é dia de futebol")
return false;
}
}
hojeSeJoga('sábado')
hojeSeJoga('domingo')
In its original code, you do not use quotation marks, which makes the function think that the right operand of the equality operator is a variable: thus, the comparison is being if something is equal to this something, that is, it always enters the first if, independent of the value of the argument passed to the function.
You mean that if
domingo
is different fromdomingo
So it’s not football day? Something likese 1 for diferente de 1
?– anonimo
Try something like
domingo === 'domingo'
– Lucas Bittencourt
And what value is passed in the parameter
hojeSeJoga(valor aqui)
? Is a string or is a numeric value, or a string in date format or is an object ofnew Date
?– Guilherme Nascimento