From f210c12d4d37ae401f029de5e280bf411719d4d6 Mon Sep 17 00:00:00 2001 From: Tim Mickel Date: Mon, 20 Jun 2016 14:42:06 -0400 Subject: [PATCH] Add more operators for testing --- src/blocks/scratch3_operators.js | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/blocks/scratch3_operators.js b/src/blocks/scratch3_operators.js index 0b4471c35..03fe3e352 100644 --- a/src/blocks/scratch3_operators.js +++ b/src/blocks/scratch3_operators.js @@ -15,7 +15,14 @@ Scratch3OperatorsBlocks.prototype.getPrimitives = function() { 'math_number': this.number, 'text': this.text, 'operator_add': this.add, + 'operator_subtract': this.subtract, + 'operator_multiply': this.multiply, + 'operator_divide': this.divide, + 'operator_lt': this.lt, 'operator_equals': this.equals, + 'operator_gt': this.gt, + 'operator_and': this.and, + 'operator_or': this.or, 'operator_random': this.random }; }; @@ -32,10 +39,45 @@ Scratch3OperatorsBlocks.prototype.add = function (args) { return args.NUM1 + args.NUM2; }; +Scratch3OperatorsBlocks.prototype.subtract = function (args) { + return args.NUM1 - args.NUM2; +}; + +Scratch3OperatorsBlocks.prototype.multiply = function (args) { + return args.NUM1 * args.NUM2; +}; + +Scratch3OperatorsBlocks.prototype.divide = function (args) { + return args.NUM1 / args.NUM2; +}; + +Scratch3OperatorsBlocks.prototype.lt = function (args) { + return args.OPERAND1 < args.OPERAND2; +}; + Scratch3OperatorsBlocks.prototype.equals = function (args) { return args.OPERAND1 == args.OPERAND2; }; +Scratch3OperatorsBlocks.prototype.gt = function (args) { + return args.OPERAND1 > args.OPERAND2; +}; + +Scratch3OperatorsBlocks.prototype.and = function (args) { + if (!args.OPERAND1 || !args.OPERAND2) { + return false; + } + return true; +}; + +Scratch3OperatorsBlocks.prototype.or = function (args) { + return args.OPERAND1 || args.OPERAND2; +}; + +Scratch3OperatorsBlocks.prototype.not = function (args) { + return !args.OPERAND; +}; + Scratch3OperatorsBlocks.prototype.random = function (args, util) { // As a demo, this implementation of random returns after 1 second of yield. // @todo Match Scratch 2.0 implementation with int-truncation.