Funciones e if / else


#1

//Escribí tu función a continuación.
//¡No te olvides de llamar a tu función!
var controlDescanso = function ( cantHoras ); {

if ( cantHoras >= 8 ); {

        return "¡Estás durmiendo suficiente! ¡Demasiado quizás!";

    } else {

            return "¡Demasiado quizás!";

        };

};

var val = cantHoras( 10 );
console.log( val );
var val = cantHoras( 5 );
console.log( val );
var val = cantHoras( 8 );
console.log( val );

me sale error...


#2

No semicolons after conditions:

if ( cantHoras >= 8 ); { // no semicolon here


#3

var controlDescanso = function ( cantHoras ); {

if ( cantHoras >= 8 ) {

    return "¡Estás durmiendo suficiente! ¡Demasiado quizás!";

} else {

        return "¡Demasiado quizás!";

    }

};

var val = cantHoras( 10 );
console.log( val );
var val = cantHoras( 5 );
console.log( val );
var val = cantHoras( 8 );
console.log( val );

aun me sale error


#4

Sry missed this one. Here the semicolon is a problem as well. Also for functions the {} is mandatory so the should not be something between ) and { other than whitespaces.


#5


#6

Ok it's too late sorry. You call a function that is called cantHoras but the real name of your function is controlDescanso so it is complaining about a name that has no value yet.


#8

no entiendo donde esta el error

var controlDescanso = function ( cantHoras ) {

if ( cantHoras >= 8 ) {

return "¡Estás durmiendo suficiente! ¡Demasiado quizás!";

} else {

 return "¡Demasiado quizás!";

}

}

controlDescanso( 10 );
controlDescanso( 5 );
controlDescanso( 8 );

Este es el mensaje de error que me sale

¡Uy! Probá otra vez. Parece que tu función no retorna "¡Cerrá los ojos un poco más!" cuando la cantHoras es 5. Controlá la sintaxis if / else y si estás usando el operador de comparación que corresponde.

Pero el operador de comparacion en >= y no consigo ver el error de sintaxis de if/else...

Llevo ya un rato estancada ...


#9

Sry for my lack of spanish, but I guess the problem is that the expected output for cantHoras < 8 is "¡Cerrá los ojos un poco más!" but your output is "¡Demasiado quizás!".


#10

Yes this is what I'm told but I don't understand, my if /el sintax seems to be ok and more than 8 hours of sleep is written >= ... can you give me the english example please? or tell me what I'm doing wrong?


#11

As said it is just about that sentence your syntax is fine and I guess the author was over interpreting the error, assuming a syntax error when it is really mostly in the category typo. The only improvement you could do to your code apart from changing the output message is to wrap your function calls in console.log to see all 3 of them instead of an echo of the last value in your code.


#12

Thanks Haxor 789, I re-writted it from the start :slightly_smiling:

function controlDescanso(cantHoras){

if (cantHoras>=8){
return "¡Estás durmiendo suficiente! ¡Demasiado quizás!";
} else {
return "¡Cerrá los ojos un poco más!";
}
}

controlDescanso(10);
controlDescanso(5);
controlDescanso(8);

... and it worked !!