Chapter 10. Animal Sounds

In this chapter, you’ll create a simple program to ask players a question and play back sounds based on the answer given. You’ll learn about JavaScript’s switch statement and ScriptCraft’s sounds module. The new program will ask players what their favorite animal is and play back that animal’s sound.

The switch Statement

In Chapter 9 you learned how to get input from players and how to test the input using JavaScript’s if statement. JavaScript provides an additional statement for testing values: the switch statement. The switch statement is useful when you want to make decisions by testing a single value. The switch statement is best explained by example. Create a new file called animalSounds.js in the scriptcraft/plugins/ ...

Get A Beginner’s Guide to Writing Minecraft Plugins in JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.