diff options
author | Linus Lee <linus@thesephist.com> | 2020-09-24 08:16:49 -0400 |
---|---|---|
committer | Linus Lee <linus@thesephist.com> | 2020-09-24 08:16:49 -0400 |
commit | e6797461f8372c6b0740d75ee73015f6ec561a68 (patch) | |
tree | bb4eaa4993fcfd92461e64b438594315c580eb02 /static/js/main.js | |
parent | 528eb9c74dc29e8f86554852862cdea941dda7a5 (diff) | |
download | tabloid-fake-closure-e6797461f8372c6b0740d75ee73015f6ec561a68.tar.gz tabloid-fake-closure-e6797461f8372c6b0740d75ee73015f6ec561a68.zip |
Add fibonacci sequence sample
Diffstat (limited to 'static/js/main.js')
-rw-r--r-- | static/js/main.js | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/static/js/main.js b/static/js/main.js index 6dc22d3..debad58 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,14 +1,12 @@ -const PROG_DEFAULT = `YOU WON'T WANT TO MISS 'Hello, World!' +const PROG_FACTORIAL = `YOU WON'T WANT TO MISS 'Hello, World!' DISCOVER HOW TO factorial WITH n WE SAID WHAT IF n IS ACTUALLY 0 - WE SAID SHOCKING DEVELOPMENT 1 - END OF STORY - LIES! WE SAID - SHOCKING DEVELOPMENT n MULTIPLY factorial OF n SUBTRACT 1 - END OF STORY + LIES! + SHOCKING DEVELOPMENT + n TIMES factorial OF n MINUS 1 END OF STORY EXPERTS CLAIM result TO BE factorial OF 10 @@ -17,6 +15,25 @@ YOU WON'T WANT TO MISS result PLEASE LIKE AND SUBSCRIBE`; +const PROG_FIBONACCI = `DISCOVER HOW TO fibonacci WITH a, b, n +WE SAID + WHAT IF n SMALLER THAN 1 + SHOCKING DEVELOPMENT b + LIES! WE SAID + YOU WON'T WANT TO MISS b + SHOCKING DEVELOPMENT + fibonacci OF b, a PLUS b, n MINUS 1 + END OF STORY +END OF STORY + +EXPERTS CLAIM limit TO BE 10 +YOU WON'T WANT TO MISS 'First 10 Fibonacci numbers' +EXPERTS CLAIM nothing TO BE fibonacci OF 1, 1, limit + +PLEASE LIKE AND SUBSCRIBE`; + +const PROG_DEFAULT = PROG_FIBONACCI; + const HEADLINES = [ `You Won't Believe What This Programming Language Can Do!`, `The Best Programming Language You Haven't Heard Of (It Will Surprise You!)`, @@ -42,10 +59,6 @@ class Editor extends Component { this.errors = ''; this.handleRun = () => this.eval(); - this.handleReset = () => { - this.prog = PROG_DEFAULT; - this.render(); - } this.handleInput = evt => { this.prog = evt.target.value; this.render(); @@ -63,6 +76,16 @@ class Editor extends Component { } } } + this.setFactorial = () => { + this.prog = PROG_FACTORIAL; + this.output = this.errors = ''; + this.render(); + } + this.setFibonacci= () => { + this.prog = PROG_FIBONACCI; + this.output = this.errors = ''; + this.render(); + } } eval() { this.output = ''; @@ -85,9 +108,10 @@ class Editor extends Component { compose() { return jdom`<div class="editor fixed block"> <div class="controls"> - ${this.prog === PROG_DEFAULT ? null : - jdom`<button class="block" - onclick=${this.handleReset}>Reset</button>`} + <button class="block" + onclick=${this.setFibonacci}>Fibonacci sample</button> + <button class="block" + onclick=${this.setFactorial}>Factorial sample</button> <button class="accent block" onclick=${this.handleRun}>Run this!</button> </div> @@ -207,12 +231,7 @@ class App extends Component { target="_blank">Ink</a>. </p> <h2>How much is there?</h2> - <p> - Here's the full list of non-standard keywords that Tabloid - currently uses, in addition to standard operators like <code - class="inline fixed block">PLUS</code> and <code class="inline - fixed block">MINUS</code>. - </p> + <p>Here's the full list of non-standard keywords that Tabloid currently uses:</p> <ul> <li><code class="inline fixed block">DISCOVER HOW TO...WITH</code> declare a function</li> <li><code class="inline fixed block">WE SAID</code> begin a block scope</li> @@ -223,6 +242,7 @@ class App extends Component { <li><code class="inline fixed block">YOU WON'T WANT TO MISS</code> print output</li> <li><code class="inline fixed block">TOTALLY RIGHT</code> true</li> <li><code class="inline fixed block">COMPLETELY WRONG</code> false</li> + <li><code class="inline fixed block">PLUS / MINUS / TIMES / DIVIDED BY / MODULO</code> the obvious arithmetic operations</li> <li><code class="inline fixed block">IS ACTUALLY</code> is equal to</li> <li><code class="inline fixed block">BEATS / SMALLER THAN</code> greater than / less than</li> <li><code class="inline fixed block">SHOCKING DEVELOPMENT</code> return from a function</li> |