Coin flip command

I am wanting to make a coin fli-p command using either JS or a simple command.

I was trying to utilize the following code:
let coinFlip = JS.utils.random(‘Heads’,‘Tails’);

JS.wizebot.send_chat_message("The coin has been flipped... and the result is " + coinFlip + "!");

Problem is it only returns false. Any advice?

Hello,

Try this :

let coinFlip_words = ["Heads", "Tails"];
let coinFlip_Index  = JS.utils.random(0, coinFlip_words.length - 1);
let randomFlip        = coinFlip_words[coinFlip_Index];

JS.wizebot.send_chat_message("The coin has been flipped... and the result is " + randomFlip + "!");

That worked. However, is there a way to add on to it to where it has a delay before sending a new chat message?

For example,

let coinFlip_words = ["Heads", "Tails"];
let coinFlip_Index  = JS.utils.random(0, coinFlip_words.length - 1);
let randomFlip        = coinFlip_words[coinFlip_Index];

JS.wizebot.send_chat_message("The coin has been flipped... and the result is ... ");

(delay for 3 seconds)

JS.wizebot.send_chat_message(randomFlip + "!")

You can use :

JS.utils.sleep(3000);

:slight_smile:

1 Like