• Create BookmarkCreate Bookmark
• Create Note or TagCreate Note or Tag
• PrintPrint

### Applied Expression Writing

This chapter is packed with concepts that relate to composing scripts. You’ve seen a couple of previews of concepts that will come up later (such as arrays and functions), but for the most part, everything in this chapter has to do with writing expressions and statements. The remaining pages provide a chance to practice writing more complex expressions. I’ll provide the objective and you should at least try to write the pseudo-code and then (if you can) the actual script. I’ll provide my solution with a translation. You should remember two things while you work through these challenges. First, my solution is just one of countless possible solutions. You might very well find a better way to solve the problem. Second, I include many made-up variables. In a real project, these variables would necessarily have their values set earlier or within a different part of the movie. For example, I might use the expression score>=80. The idea is that the variable score is one that I’ve been tracking. Perhaps, attached to the button for each correct answer, I used the script: score=score+10;. I’m just assuming that such variables have had their values set properly already. You can make up variables to use in expressions—just realize that you’ll have to take care of them by changing their values, as necessary.

#### Objective:

Given a minimum (x location, for example) and a maximum x, write an expression that uses a given percent to return an integer midpoint based on percent. That is, if the west coast is at 100 miles longitude and the east coast is at 3100 miles longitude, a location 50 percent across the country would be at longitude position 1600 miles. Even though most people can figure that out in their head, it’s more difficult to write the expression (using variables named high, low, and percent).

PREVIEW

Not a subscriber?

Start A Free Trial

• Create BookmarkCreate Bookmark
• Create Note or TagCreate Note or Tag
• PrintPrint