One of the most common suggestions when it comes to writing is to omit needless words, and it applies just as much to writing Ruby as writing stories.

There are two control structures to change here:

  1. The unless block:

    unless n.is_a? Integer return "n must be an integer." end
  2. The if block below the unless block:

    if n <= 0 return "n must be greater than 0." end

Both blocks can be simplified using the zen of Ruby!



Refactor the code in the editor to use single-line ifs and unlesss.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?