0

Pig Latin, Error Code

New to coding....It is giving me an error on the word “new”. I keep tweeking little things but I can not get it to run. I added notes just to make sure my thinking was correct. What am I missing? user=gets.chomp #split words into array of substrings words=user.split("") words.new = [] words.each do |word| #take away one index base = words.length - 1 #start at index 1 until (index -1) count ends, add first letter, add "ay" words.new << (word[1..base] + word[0] + "ay") end puts words.new.join ("")

9th Dec 2020, 10:15 AM
Joy Shadburn
Joy Shadburn - avatar
2 Answers
+ 2
Joy Shadburn , the array initialization in your code is wrong. Either use for example words = [] or words = Array.new. At the end join the new words by whitespace. Look at the corrected code. Hope it helps you. https://code.sololearn.com/c57Hs7Xn0B6z/?ref=app
9th Dec 2020, 10:55 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
TheWh¡teCat 🇧🇬 Thank you, I’m glad at least the majority of my code was right. Only been coding for three weeks so this helps.
9th Dec 2020, 1:54 PM
Joy Shadburn
Joy Shadburn - avatar