瀏覽代碼

Implement the other arithmetic operators

Implemented multiplication, division, and modulo.
ApisNecros 1 年之前
父節點
當前提交
09c9bc3028
共有 1 個文件被更改,包括 18 次插入0 次删除
  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;