Simple program

Here is a simple code I wrote for reference. It may or may not help new coders. I dunno. I just got a little bored and wanted to do this little cute program

# Using # makes a grayed out line for comments so that they do not interfere with the code!

=begin

Using the =begin and =end makes it so anything you put inbetween them will be a comment!

=end

#So lets make us a "New word genaretor".

#First step is to make a nice looking title so people usually like using slashes
#To make a cool border and their title. So lets try doing that.

#First thing is we put a puts command,, easy right?

puts "////////////////////////////////////////////"

#Remember we have to use qoutation marks to make it a string("").
#Now I will copy and paste tha to make it my bottom 
puts "//       The Random Word Genaretor!       //"

puts "////////////////////////////////////////////"

#Now I will try it out and see how it looks like!

#It should look like this.

=begin 

////////////////////////////////////////////
//       The Random Word Genaretor!       //
////////////////////////////////////////////

=end

#Looks good to me!

#Now lets use the puts again and introduce them to this simple program.

puts "Welcome to the T.R.W.G. The way this works is you put in a word or letters and then another word and we combine them for you and once we do you will have a brand new word!"
puts " "
#Great introduction!

#Now lets ask them for a word

puts "Can I have a word or some random letters in the form of a word? Thanks!"
puts " "
#Now lets their answer and store it in a variable.

word1 = gets.chomp

# 'word1' is the variable and 'gets.chomp' is what puts whatever the user typed into that variable.

#Now lets ask them for another word.

puts "Can I have another word or a random set of letters in a word?"
puts " "
#Now lets get their input again.

word2 = gets.chomp

#Now we can either make a method containing of the process of combining both words or we can have it in the core of the program.

#I forgot how to do methods but I can still code it into the core of the program.

#Now let us work with a dash of magic.

#Magic is happening below here.

puts "Working our magic to create a new word for you!"
puts " "

word3 = word1 + word2 

puts "Done!"
puts " "

puts "Your new word is #{word3}."
puts " "
puts "What a great word! Want to give it a defanition?(Y/N)"
answer = gets.chomp
puts " "

if answer == "y"
    answer = "Y"
elsif answer == "n"
    answer = "N"
end

until answer == "Y" or answer == "N"
    
    puts "You did not choose Y or N. Please choose one!"
    answer = gets.chomp
    
        if answer == "y"
        answer = "Y"
    elsif answer == "n"
        answer = "N"
    end
end   

if answer == "N" 
    puts " "
    puts "Well we can give one for you!"
    defi = "Something that is awesome!"
elsif answer == "Y"
    puts" "
    puts "Please put your defanition below!"
    defi = gets.chomp
end

puts " "
puts "Word: #{word3}"
puts " "
puts "Defanition: #{defi}"
puts " "
puts "Good job, thank you for using the program!"


#Magic is happening above here.

# All done! Now you have a simple program in Ruby to combine words and make a nice little template for them!
1 Like

Moved this to the right category :slight_smile: Nice job!

Meh, I have been coding on and off so I took the Ruby course already like 5 times as a refresher course.

1 Like