3/7 Omit needless words


#1

https://www.codecademy.com/en/courses/learn-ruby/lessons/the-refactor-factory/exercises/omit-needless-words?action=lesson_resume&link_content_target=interstitial_lesson

When I click run it takes ages to process and then nothing happens it just marks me wrong and I’m unable to move on. There’s no error message. Please can someone point out my error?


$VERBOSE = nil    # We'll explain this at the end of the lesson.
require 'prime'   # This is a module. We'll cover these soon!

def first_n_primes(n)

  puts "n must be an integer." unless n.is_a? Integer

	puts "n must be greater than 0" if n <= 0
  
  prime_array ||= [] 
  
  prime = Prime.new
  for num in (1..n)
    prime_array.push(prime.next)
  end
  return prime_array
end

first_n_primes(10)



#2

Nevermind. I tried it with return a few times and it didn’t work so tried puts. return should work, not sure why it didn’t work for me the first time but it’s ok now.

return “n must be an integer.” unless n.is_a? Integer
return “n must be greater than 0.” if n <= 0


#3

That should be a return not puts so that the function is exited. Same with the line that follows.


#4

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