11 Iterating Over Arrays


#1

languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

don't know what to put


#2

I'm in the same boat right now


#3

languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]
languages.each { |element| puts element }

Originally was encountering problems with this exercise however I found this to work.


#4

thanks it worked but thanks


#5

As usual, we can use any placeholder name for the bit between two | | characters.

But i use X as my placeholder name, it wont't work...

Anyone know what happened to the ruby compiler ???


#6

Hi, what is the difference bw the following codes.

languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]
languages.each { |element| puts element }

languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]
languages.each { |element| puts "#{element}" }


#7

The problem is that you need to put a element in the place holder, such as 'X' and you need to use the same element in the placeholder and write 'puts X' . So it should end up like:

languages =["HTML", "CSS", "JavaScript", "Python", "Ruby"]
languages.each { |x| puts x }


#8

hi my friend
see this link, it's will answer your question ClickHere
i hope you a successful learning :slightly_smiling:


#9

I have tried this technique and I still have no luck getting this submitted...


#10

languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]
languages.each = { |x| puts "#{x}" }

And this results with an error below. I am confused.. we should have | right?:

(ruby):1: syntax error, unexpected '|', expecting '}'
languages.each = { |x| puts "#{x}" }
^
(ruby):1: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
languages.each = { |x| puts "#{x}" }
^
(ruby):1: syntax error, unexpected '}', expecting $end


#11

Delete the equal sign after the languages.each part and your code should work.
So it should be like this

languages.each { |x| puts "#{x}" }


#12

U got it TksU got it TksU got it Tks