JavaScript - Append Text to a Draft

Still working to figure out JavaScript here - trying to set up a front-end for sending text to Fantastical and append text to a draft that contains the calendar type. In this simple example below, every time I run the script - and no matter whether I press Work or Home button, the text from the first if statement is added (" /Calendar"). It seems like I am passing the button pressed to the variable in the if statements. Is there something else I am missing here?

Thanks for any pointers!

  Ask for a calendar type, add tag to draft based on calendar type

// setup calendar categories
const categories = ["Work", "Home"];

// prompt to select a category
var p = Prompt.create();
p.title = "Select calendar";
for (var cat of categories) {

if ( { // user made a selection
        var calendar = p.buttonPressed;

var d = draft;

   if (calendar = "Work") {
       d.content = d.content + " /Calendar "
   } else if (calendar = "Home") {
       d.content = d.content + " /Outlook "
   } else {

} else {

You need double equal for comparisons inside the if:

calendar == “xxxx”

1 Like

Yep - worked like a charm! Thanks so much.

and triple === would be even better

( identity is safer and faster than equality )

(see under the ‘evil twins’ == and != )

Triple it is! Thanks for all the pointers in this thread. Back to my JavaScript book…

1 Like