what's wrong? ` def solution(n) multiples = [] (1..n).each do |x| if x % 15 == 0 multiples << x end if x < 0 return 0 end return multiples.sum end` in ruby

The provided code has a few syntax errors. Here's the corrected version:

main.rb
def solution(n)
  multiples = []
  
  (1..n).each do |x|
    if x % 15 == 0
      multiples << x
    end
    
    if x < 0
      return 0
    end
  end
  
  return multiples.sum
end
182 chars
16 lines
  • The def solution(n) line was missing an opening parenthesis.
  • The multiples variable was not properly defined with an assignment operator.
  • The closing end statement for the each loop was missing.
  • The if x < 0 condition was not properly aligned with the previous if statement.
  • The return multiples.sum line was not aligned with the initial def solution(n) line.

These corrections should resolve the syntax issues in the code.

related categories

gistlibby LogSnag