My daughter and I are kind of at a stand still with Ruby on our PC using "Atom". Would anyone kindly help us figure this out? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

My daughter and I are kind of at a stand still with Ruby on our PC using "Atom". Would anyone kindly help us figure this out?

[EDITED] https://code.sololearn.com/cAQEjRpsT5TY/?ref=app

2nd Feb 2018, 9:58 PM
Kelsie Perry
Kelsie Perry - avatar
4 Answers
+ 7
Code Playground doesn't provide a live console, so you have to input everything in one go before the program runs. Split your input into multiple lines, e.g. 5 a o I just reviewed your latest version of the code, you're almost there. You might want to convert shape_size to integer via .to_i, fix some syntax errors (gets, end) and you're done.
3rd Feb 2018, 1:00 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
@Hatsy Rei is right there needs to be an integer conversion. The input was setup incorrectly and here is the fix. # # Ruby for Kids Project 4: Shapes # Programmed By: KP # Experiment with drawing ASCII art Shapes using code. # puts "Welcome to Shapes" print "How big do you want your shape? " shape_size = gets.chomp puts shape_size print "Outside letter: " outside_letter = gets.chomp print outside_letter print "Inside letter: " inside_letter = gets.chomp puts "About to draw a shape #{shape_size} big" puts "using #{outside_letter} for the edge" puts "and #{inside_letter} for the inside" height = shape_size width = shape_size 1.upto(height) do |row| # drawing code goes here if row == 1 puts outside_letter * width elsif row == height puts outside_letter * width else middle = inside_letter * (width - 2) puts "#{outside_letter} #{middle} #{inside_letter}" end end =begin When =begin is on the start of a line, everythinf is a comment untila line is found with = end at the beginning of a line. I used this to comment everything after the shape_size to locate some problems with the code. notice the change to gets.chomp =end #this is where it says "Looks like your program needs input" #then "split multiple inputs into seperate lines" # this is where im stuck..
3rd Feb 2018, 3:15 AM
SQrL
SQrL - avatar
+ 3
I'm thinking shape size would determine the width and height of the shape. E.g. shape size 8 would mean a square of 8*8. In this case (8), we will be printing 8 lines, each containing 8 characters. The topmost and the bottommost line which represents two of four edges would be filled with outside_letter. The remaining 6 (8-2) lines in between would begin and end with outside_letter, and 6 characters in between would be filled with inside_letter. shape_size = 5 outside_letter = a inside_letter = o Output : aaaaa # topmost line aoooa aoooa # (shape_size - 2) lines in mid aoooa aaaaa # bottommost line What I just said directly translates to: puts (outside_letter * shape_size) + "\n" + (outside_letter + (inside_letter * (shape_size - 2))+ outside_letter + "\n") * (shape_size - 2) + (outside_letter * shape_size) I'm not proficient at Ruby, there's probably a better way than this. https://code.sololearn.com/cLR4fuXW91YK/?ref=app
3rd Feb 2018, 12:22 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
i changed a few things and added a few comments at the end.. im still a bit confused
3rd Feb 2018, 12:52 AM
Kelsie Perry
Kelsie Perry - avatar