Breaking Functions
You have some idea of how powerful functions are. But beware for theyâre easy to break in lots of different ways. We saw some of this back in Chapter 2, âDebugging: Fixing Code When Things Go Wrongâ. Now that we understand functions better, itâs worth taking another look at breaking them.
The most common thing to do is forget a curly brace:
â | âfunctionâ r(max) |
â | âifâ (max) âreturnâ max * Math.random(); |
â | âreturnâ Math.random(); |
â | } |
Itâs hard to miss that error! The error messages donât say that we forgot the curly brace, which would be more helpful. But itâs pretty clear that something ...
Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.