Online Book Reader

Home Category

HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [144]

By Root 1605 0
he’s an L337 94m3r (translation: elite gamer). Figure 2-6 shows a few tosses of the coin.

I don’t know why the referee is sometimes a surfer and sometimes an L337 94m3r. Perhaps he faced a particularly bizarre set of childhood circumstances.

Figure 2-6: Heads or tails? Surfer or gamer?

What’s this L337 stuff?

Leet (L337) is a wacky social phenomenon primarily born of the online gaming community. Originally, it began as people tried to create unique screen names for multiplayer games. If you wanted to call yourself “gamer,” for example, you’d usually find the name already taken. Enterprising gamers started substituting similar-looking letters and numbers (and sometimes creative spelling) to make original names that are still somewhat readable. The practice spread, and now it’s combined with text messaging and online chat shortcuts as a sort of geek code. Get it? L337 94m3r is Leet Gamer, or Elite Gamer.

This example is getting pretty strange, so you may as well look at some code:


Building the nested conditions

If you understand how nested if structures work, you can see how the code all fits together.

1. Flip a coin.

I just used a variation of the die-rolling technique, described in the earlier sections. A coin can be only heads or tails, so I rolled a value that would be 1 or 2 for the coin variable.

2. Flip another coin for the personality.

The referee’s persona is reflected in another random value between 1 and 2.

3. Check to see whether you have a surfer.

If the character roll is 1, we have a surfer, so set up an if statement to handle the surfer’s output.

4. If it’s the surfer, check the coin toss.

Now that you know a surfer is speaking, check the coin for heads or tails. Another if statement handles this task.

5. Respond to the coin toss in surfer-speak.

Use alert() statements to output the result in the surfer dialect.

6. Handle the L337 character.

The outer if structure determines which character is speaking. The else clause of this case will happen if character is not 1, so all the LEET stuff goes in the else clause.

7. Check the coin again.

Now that you know you’re speaking in gamer code, determine what to say by consulting the coin in another if statement.


Making sense of nested ifs

Nested if structures aren’t all that difficult, but they can be messy, especially when you get several layers deep (as you will, eventually). The following tips help make sure that everything makes sense:

♦ Watch your indentation. Be vigilant on your indentation scheme. An editor like Aptana, which automatically indents your code, is a big plus. Indentation is a great way to tell what level of code you’re on.

♦ Use comments. You can easily get lost in the logic of a nested condition. Add comments liberally so that you can remind yourself where you are in the logic. I specify which if statement is ending.

♦ Test your code. Just because you think it works doesn’t mean it will. Surprises will happen. Test thoroughly to make sure that the code does what you think it should do.

Chapter 3: Loops and Debugging

In This Chapter

Working with for loops

Building while loops

Recognizing troublesome loops

Catching crashes and logic errors

Using the Aptana line-by-line debugger


Computer programs can do repetitive tasks easily, thanks to a series of constructs called loops. In this chapter, you discover the two major techniques for managing loops.

Loops are powerful, but they can be dangerous. It’s possible to create loops that act improperly, and these

Return Main Page Previous Page Next Page

®Online Book Reader