Ver código fonte

Implement the other arithmetic operators

Implemented multiplication, division, and modulo.
ApisNecros 1 ano atrás
pai
commit
09c9bc3028
1 arquivos alterados com 18 adições e 0 exclusões
  1. 18 0
      starfish.js

+ 18 - 0
starfish.js

@@ -182,6 +182,24 @@ class CodeBox {
                 this.stack.Push(x - y);
                 break;
             }
+            case "*": {
+                const x = this.stack.Pop();
+                const y = this.stack.Pop();
+                this.stack.Push(x * y);
+                break;
+            }
+            case ",": {
+                const x = this.stack.Pop();
+                const y = this.stack.Pop();
+                this.stack.Push(x / y);
+                break;
+            }
+            case "%": {
+                const x = this.stack.Pop();
+                const y = this.stack.Pop();
+                this.stack.Push(x % y);
+                break;
+            }
             case "n": 
                 output = this.stack.Pop();
                 break;