In the last exercise, the tests chose the arguments, called your functions, and checked what came back. That’s useful feedback, but you only saw the verdicts. A local script works the other way around. It’s your file, so you choose the calls, run it whenever you like, and see every result in the terminal.
In this short lesson, you’ll move one function you wrote on-site into a local script, call it with your own values, and then add a small helper of your own beside it.
Copy a Function Into a Scratch File
Open the last exercise, pick one of your three functions, and copy it from its comment down to its closing brace. Then create a new file in your scratch/ folder and paste it in. The examples here use prizeFor(), but the steps are the same for any of them:
// Take a number of prize tickets and return the prize
// they're worth
function prizeFor(tickets) {
if (tickets < 50) {
return "sticker";
} else if (tickets < 200) {
return "yo-yo";
} else {
return "teddy bear";
}
}