[prev]Web 2.0 Madlibs[next]

Let's put together the main concepts of the past few lessons.

Example: Web 2.0 Madlibs

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
printp(image("http://i35.tinypic.com/214a0c8.gif"))

if (request.path == "/") {
  print(html("<h2>Web 2.0 Madlibs!</h2>"))
  print(form("/submit", "company name",
   "noun", "plural noun", "adjective 1",
   "adjective 2", "verb"))
}

if (request.path == "/submit") {
  printp(request.param("company name"), "'s ",
    request.param("adjective 1"),
    " new strategy is to leverage ",
    request.param("plural noun"),
    ", utilize the ",
    request.param("adjective 2"),
    " web, and ", request.param("verb"),
    " the ", request.param("noun"),
    "-osphere.")

  printp(link("/", "back"))
}

Click to run the code.

This madlibs app generates corporate strategies for web 2.0 companies. Try it out!

Lines 3-8 handle the initial request to the app. We use the form command to prompt the user for many different parts of speech. The form submits the user's input to the path "/submit".

Lines 10-22 handle requests to the path "/submit". We use request.param() to get the user's chosen words, and then print those words back to the user along with other text strings that form a complete sentence. As with other commands, we separate the arguments with commas (,). But don't get confused by the text strings that contain commas themselves!

Finally, the close-parenthesis on line 19 ends the printp( command that started on line 11.

Exercise: Make your own madlib. Use the "new app from this" button on the right side below the code to create your own madlibs app and publish it for the world to see. When you're done, post a link to it here in the forum so other people can see what you've created!


Congratulations! You've completed the first section of this guide. Take a moment to play around with the above app (especially if you haven't been playing around with the other examples!) before continuing. Remember, the best way to learn programming is to practice fiddling with existing apps. You can copy any example app in this guide and make it your own, by clicking the "new app from this" link below any example.

If you get stuck trying to do something, don't be shy about asking for help in the AppJet Forums. It's normal to have some questions when you're learning something new. And if you can answer someone else's question, then you gain programmer's karma which comes in handy all the time!

Previous Lesson: HTML (attributes) Next Lesson: Programming