Question: Help my homework! PHPHomework 4: Lorem Ipsum Generator This fun homework assignment will be a portfolio gem! You will create your own Lorem Ipsum generator
Help my homework!
PHPHomework 4: Lorem Ipsum Generator This fun homework assignment will be a portfolio gem! You will create your own Lorem Ipsum generator based on a topic of your choice.
What is a Lorem Ipsum generator?
- "Lorem ipsum is a placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups." - from loremipsum.io site
We use it a lot when designing layouts for web clients too. Here are some of my favorites to get some of your own ideas:
- Bacon Ipsum (Links to an external site.)
- Zombie Ipsum (Links to an external site.)
- Cat Ipsum (Links to an external site.)
- Hipster Ipsum (Links to an external site.)
(There are tons out there! So this works with pretty much any topic you can think of!)
You can set this up however you would like to, but here are the requirements.
- You must use at least ONE array of words.
- You must randomly generate sentences using the words from your array.
- Your site visitor will need to select at least how many paragraphs they want you to output.
- Use CSS to style your page in the theme of your topic.
- Use a minimum of ONE image on all of your web pages.
- You must use at least two loops in your program. You might want to use more. Depends on how you set this up.
Step 1: Think the problem through
Okay, if I asked you to do this for me on paper, how would you go about doing it?
Let's say I gave you 100 notecards and each notecard had a word on it related to my theme of weather. Your job is to create a sentence out of those words. I give you a seven sided dice with the numbers 6, 7, 8, 9, 10, 11, and 12 on it. How would you create the first sentence?
In my mind, I would first shuffle the cards to mix them up. Then I would roll the dice. Let's say I get the number 8. I would use the number 8 to randomly grab 8 words from my list of cards. This 8 represents how many words will be in my first randomly created sentence. Then I will put the notecards in order of how I pulled them out and there is my first sentence. I would write down the sentence and use a capital letter for the first word and end in a period (or some other ending punctuation mark). I would repeat this for 3-5 sentences until I formed a paragraph.
Step 2: Write your solution in pseudocode
Now that you have some basic understanding on how YOU might do this in the physical world, let's translate this to pseudocode. Pseudocode uses natural language like notes explaining how you would do your steps in coding without actually coding. These steps make great comments for your code and a great place to start. It might looks something like this. Everyone will have their own way of doing things.
# Create form with select box for total number of paragraphs (1-10?) as a required field
# Upon form submission, create sentences from pre-populated array of 100 words. ex: array word_list
# Create a loop that will generate between 3 to 5 sentences.
# Generate a random number for the total words in sentence. ex: int total_words
# Use a loop that will loop for the total_words and randomly select an index from my word_list array and save the value of that array item to a string variable my_sentence.
# Output the my_sentence string.
# Done with this loop iteration, continue these steps until loop is completed
Step 3: Write your code to match the pseudocode
Here is my example code from my thought process. When I code, I like to start small (in this case by creating just one sentence) and then once it is working, I can add more complexity to it. Feel free to start with this code and build upon it.
Formatted sentence : " . ucfirst(trim($this_sentence)) . "."; ?>
Include a link at the bottom of the form that links back to the main page in the event that users would like to create more lorem ipsum.
Save your files in your homework4 subfolder.
To Submit:
Upload a zipped folder containing all of your files. Submit your website URL in the assignment comments section for the main page of your website.
Some Tips:
- Be sure to include several of the most popular words used in sentences (Links to an external site.) so that your sentences somewhat make sense.
- Locate a terminology website for your topic to populate your array of words.
- Advanced programmers can make use of a function for this process if you wish to. See Chapter 3 for function syntax.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
