Hi! Im new to programming (and Ruby of course) and am working through Chris Pine’s tutorial as a starting point. At the end of chapter 7 there is a ‘A Few Things to Try’ project where you rewrite the Table of Contents program to utilize arrays. Id like to house the information (ie Chapter Title and Page) in two seperate arrays and then cycle through code for each string in each array at the same time (hopefully this makes sense..).
Here is the code that Ive come up with (but of course doesnt work):
page_width = 50 contents = ['Chapter 1: Getting Started','Chapter 2: Numbers','Chapter 3: Letters'] pages = ['1','9','13'] contents.each do |content| and pages.each do |page| puts(content.ljust(page_width/2)) + (page.rjust(page_width/2)) end
Im confident that Im going about this the wrong way…any hints?