The cardid property represent the card exemplar... ie, THE "The Lovers" card. Once you play the card to the table, what you see on the VTT is a graphic object with a subtype = card and a cardid equal to the ID of the exemplar.
If you want to rotate something on the board, you want the ID of THAT graphic object.
Here's some code to return all instances of a card-graphic on the user's page that are connected to a specific cardid you supply:
const getPageForPlayer = (playerid) => {
let player = getObj('player', playerid);
if (playerIsGM(playerid)) {
return player.get('lastpage') || Campaign().get('playerpageid');
}
let psp = Campaign().get('playerspecificpages');
if (psp[playerid]) {
return psp[playerid];
}
return Campaign().get('playerpageid');
};
const getCardOnVTT = (cardid, playerid) => findObjs({ type: 'graphic', subtype: 'card', pageid: getPageForPlayer(playerid), cardid: cardid})[0];
You'd call it with someting like:
let cardGraphic = getCardOnVtt(cardid, msg.playerid);
Also, Roll20 exposes a rollInteger() function that lets you use their Quantum Die Roller to generate numbers with significantly less modulo bias. In your case, instead of your Math operation, just assign your variable to the result of this function:
let ranNum = rollInteger(2);
And, finally, if you want to see how these objects relate to each other, or you need to take a deep dive on an object's properties, consider using my Inspector script. It would let you flow from one panel of information to another.
For instance, a good place to start would be to select a card on your page, then run:
!inspect --selected

Then hit the little magnifying glass button to inspect the object with THAT ID... from the resulting panel, you can see the object type, subtype, and cardID...

From that cardid you could flow to the data panel for the card exemplar... but I think by now you get the point. Inspector can be super useful.