Let’s improve the HELLO WORLD pack. We’re going to create a new formula that says “hello” as many times as the user wants it to.
Specifically, we’d like to create a formula MultiHello that takes a number input, returning the world “Hello” that many times, e.g. MultiHello(3) → “Hello Hello Hello!”
1. Add a formula
Let’s go back to our code window. Type in /formula while in the coding window, and you’ll receive the basic skeleton to define a new formula
Next, let’s fill in this skeleton by giving it a name, description, and changing the parameter and function. Read along with the comments in the code skeleton to see what each line does. Note, you’ll have to change the type for the parameter to be a number.
Click “Create Build” again, just as you did to create the first version of your Pack.
If you have issues that prevent Coda from compiling the Pack — e.g. basic syntax errors, you forgot to specify a required field — you’ll get an error in the Debug panel, as shown below; in this example, we forgot to include a close ” on Line 59.
Once you succeed, you’ll get a confirmation message that the build succeeded
3. In-doc (run-time) debugging
You can see in-doc, i.e. run-time, errors in the doc itself as well. You can directly print to it from your code too using console.log() just as you normally would.
Go back to the doc you’d created to test the Hello World Pack. Go to the settings panel of the Pack and select "Latest Version.” You’ll notice that it’s been auto-updated to the latest version now and whenever you submit any new versions.
You can now test the new formula and see it in action!
You can access the debug log from this same panel. This panel includes logs of when features were invoked in the doc and even user-triggered messages and errors via console.log.