Sfoglia il codice sorgente

Implement the other arithmetic operators

Implemented multiplication, division, and modulo.
ApisNecros 1 anno fa
parent
commit
09c9bc3028
1 ha cambiato i file con 18 aggiunte e 0 eliminazioni
  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;