Can't pass boolean parameter


#1

https://www.codecademy.com/courses/learn-ruby/lessons/ordering-your-library/exercises/sorting-with-control-flow

when I pass the “true” parameter when calling the method I get a syntax error.
(ruby):11: syntax error, unexpected ‘,’, expecting ')'
alphabetize (numbers,true)
^



numbers = [12,321,12,54,456,23]

def alphabetize(arr, rev=false)
  arr.sort!
  if rev == true
    puts arr.reverse!
  else
    puts arr
  end
end

alphabetize (numbers,true)



#2

It tried using


alphabetize(numbers,true)
puts "====" 
alphabetize(numbers)

and got the output


456
321
54
23
12
12
====
12
12
23
54
321
456

++++ reset of session *****************
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#3

i copied the code into sublime text and used the build function, it still gives me the same error. Could this be something with the difference between ruby 1.8 and 1.9?


#4

ok, your code helped me find the problem. I leaving a space " " between the method and the parameter like so: alphabetize (numbers,true). If I remove the “space” just like you did, the code works. What’s odd is that alphabetize" "(numbers) works just fine


#5

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