Https://www.codecademy.com/courses/learn-ruby/lessons/the-refactor-factory/exercises/omit-needless-words?action=lesson_resume


#1

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

The Refactor Factory - 3. Omit Needless Words - SCT Error

Hi Guys,

I keep getting an SCT Error when I try to run my code. I'm not entirely sure what an SCT Error is but from what I've looked up it seems to be a code-checker issue.

Any help would be much appreciated. Thanks.

My code is:

Blockquote

$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

Had the same issue - SCT Error. Turns out the "puts" should be "return" since a return is expected.

$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)

  return "n must be an integer." unless n.is_a? Integer
  return "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)

#3

Ahh! My bad.

Thanks @goodvibeschi , saved my bacon!


#4

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