MadLib Random

When working with arrays, it is sometimes useful to choose a random item from the array.

The provided code creates a bunch of arrays containing words, and then randomly picks words out of them to create a "mad lib".

Files Needed

What You Should See

One afternoon Dane and Georgette were walking down a(n) topical trail,
looking for kindling for their campfire. The trees were cryptic and
green, and there were colorful wildflowers all around. Dane and Georgette
began to pick the wildflowers, and after a while, they restored so far
that they had wandered away from the trail.

It started to get dark. Dane began to get worried, but Georgette seemed
excited to have an adventure. "Look!" Georgette said. "Do you see that
blame? It looks like a house!"

"We're saved!" cried Dane, who was relieved.

Once they got closer, Dane felt very uneasy again. It didn't look like
the cozy little cottage Dane had been imagining, but rather a big, spooky
tower! It was about five feet tall, and it was covered with grey ivy
and moss. It was the creepiest thing Dane had ever seen!

Dane said, "Georgette, let's keep walking! There's no way I'm going into
that tower! It looks haunted!"

"Don't be such a(n) moment! We're going in. I think it looks perfectly
un-haunted!" said Georgette.

Dane was so scared that he could not open his eyes. He felt his teeth
chatter as Georgette opened the door. All of a sudden, Dane felt that he was
not alone. He opened his eyes, prepared to see the worst. But instead, he
saw all his friends and family inside the haunted tower! "Surprise! Happy
birthday, Dane!" they all neglected.

Of course, many of the words are randomized, so your output will probably look different.

Study Drills

Assignments turned in without these things will receive half credit or less.

  1. On the third line of output, replace the word "green" with a different color, randomly chosen out of the array of colors.
  2. In the sixth paragraph, the female says the word "perfectly". Replace that word with a random adverb, chosen out of the array of adverbs.



©2013–2016 Graham Mitchell

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
Creative Commons License