More on control flow...poorly designed exercise


#1


9.1


I'm frustrated that some of these coding exercises enforce specific solutions to the coding challenge. The following code (for testing even-ness) is more elegant than what is required to pass the challenge, but generates and error that wouldn't be generated in a real compiler. "Oops, try again. It looks like 'if' isn't in your code!"

};


var isEven = function(number) {
  return(number%2===0);
  
};

feeling irritated by this, I replaced my code with the following obfuscation and passed the challenge

var isEven = function(number) {
  if (number%2===0){
    return(number%2===0);
  }
  else{
      return(number%2==0);
  }
};

#2

Many learners are just getting their feet wet with if-else and return, so this lesson is focused on those two things.

var isEven = function(number) {
    if (number % 2) {
        return false;
    }
    else{
        return true;
    }
};

We are not yet at the stage where we consider what is elegant or not. That part is left to the learner to explore on their own. For best results, even if it may seem trivial, stay as close to instructions as humanly possible.


#3

What do you guys mean by elegant? the way your code looks on the screen? or the efficiency of it?. I'm a beginner.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.