Flatiron Blog #2 - Fruit Loops

nerdyandnatural

Sarah Williams

Posted on May 19, 2019

Flatiron Blog #2 - Fruit Loops

So the first month of Flatiron has been a whirlwind of new information. All these arrays, loops, iterations, OOR. All this information has me feeling loopy (get it?)

But I feel like I'm not retaining the information as well as I should. I have been doing the challenges but I feel like I need to "build" on my own. Building things on my own has helped me a lot with retaining info.

So I decided to start building. I started simple: getting ruby to generate fruit when prompted. I call it Fruit Loops (someone on Twitter gave me the idea). Here is the code (you can also view it here )

So what happens is that the code is going to great you and ask if you want some fruit. If you answer yes, the code will randomly select a fruit from the array and give you some; then the program will end. If you say no, the program will say bye and end. If you say anything else (like ask it a question) it will reloop and re-ask you the question until you answer yes or no.

This was a great review of array and loops. But I'm having difficulty trying to use regex for this. You see, I want it to be able to select various answers of "yes" and "no" and not just "yes" and "no". But with a little more studying I'll probably will have it down next time.

I also started a mini project called "Free Fruit Fridays". Here's the code (Also here

This isn't finished and the code needs work. But the idea is this: It's free fruit friday and the market is giving away 500 pieces of fruit to every customer that comes in. But, how will they be able to properly distribute the fruit to the customers and keep track? The generator starts by asking for the name of the customer and then asking how many pieces of fruit they want. Then it will randomly give then that # of random fruit. The process repeats until it runs out and then the generator will say that there is no more fruit.

I'm using similar methods that were in the previous experiment but I can't stop the loop from generating endlessly and need to figure out how to get it back to the beginning. I'm thinking of going more advanced on this one and using OOR. But it looks like I got Arrays and Loops down finally.

Ruby isn't so bad after all. Maybe by the next post I'll be doing advanced OOR.

💖 💪 🙅 🚩
nerdyandnatural
Sarah Williams

Posted on May 19, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Flatiron Blog #2 - Fruit Loops
flatiron Flatiron Blog #2 - Fruit Loops

May 19, 2019

Grabbing Coffee with MVC
flatiron Grabbing Coffee with MVC

August 12, 2020