Plus sur le contrôle de flux en JS ex 1 / More about flux control in JS ex 1


#1

Voici mon code / Here is my code

var estPair = function(nombre) {
if( estPair % 2 ) {
return true;
} else {
return false;
}
};

Le code semble bon mais un message d'erreur s'affiche "Oups, merci de réessayer. On dirait que votre fonction retourne false quand nombre = 2. Vérifiez que votre code dans la déclaration 'if' / 'else' retourne (return) bien true si le nombre qu'il reçoit est pair."

The code seems to be good, but an error message appear "Oups, please retry. It seems your function return false when nombre = 2. Check your code in 'if/else' declaration return true if the number is pair"

Quelqu'un pourrait il m'aider ? / May someone help me ?


#2

if (nombre % 2) {

estPair is the name of the function, nombre is the name of the formal parameter we hand into the function to operate upon. Be very careful in future to not use a function name inside a function. This will result in a circular reference or infinite loop. Not a happy day if you haven't saved your work.


#3

Thanks for your answer. Saddly, I've tried what you wrote, but nothing has changed :confused:


#4

I didn't reveal everything I saw, in the off chance you might discover more as you made repairs. This parity checker program returns true for even, and false for odd. At least that's the design. If the remainder is 1, nombre % 2 is True. That means we have to switch up the results.