Hi everyone,
I created a block that returns a random string, but the problem is that I am not able to print it, here is my code:
Blockly.Blocks['joke'] = {
init: function () {
this.appendDummyInput()
.appendField("Tell a random joke");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setOutput(true, 'String');
this.setColour(290);
this.setTooltip("Tooltip text");
this.setHelpUrl("");
}
};
javascript.javascriptGenerator.forBlock['joke'] = function (block) {
let jokes = ["joke 1", "joke 2", "joke 3", "joke 4", "joke 5", "joke 6", "joke 7", "joke 8", "joke 9", "joke 10"];
let random = Math.floor(Math.random() * jokes.length);
let code = "return " + jokes[random] + "";
return code;
};
It returns the random string but not inside the alert function :(
what am I doing wrong? I just started with Blockly and I am still figuring it all out.
Thank you !