├── README.md └── web-workers └── fibonacci-worker ├── README.md ├── fibonacci.js └── index.html /README.md: -------------------------------------------------------------------------------- 1 | # fibonacci-worker 2 | 3 | > NOTE: This example repository has been archived. The example code and live example can now be found at [dom-examples/web-workers/fibonacci-worker](https://github.com/mdn/dom-examples/tree/main/web-workers/fibonacci-worker) 4 | -------------------------------------------------------------------------------- /web-workers/fibonacci-worker/README.md: -------------------------------------------------------------------------------- 1 | # fibonacci-worker 2 | > NOTE: This example repository has been archived. The example code and live example can now be found at [dom-examples/web-workers/fibonacci-worker](https://github.com/mdn/dom-examples/tree/master/web-workers/fibonacci-worker) 3 | -------------------------------------------------------------------------------- /web-workers/fibonacci-worker/fibonacci.js: -------------------------------------------------------------------------------- 1 | self.onmessage = function(e) { 2 | let userNum = Number(e.data); 3 | fibonacci(userNum); 4 | } 5 | 6 | 7 | function fibonacci(num){ 8 | let a = 1, b = 0, temp; 9 | while (num >= 0){ 10 | temp = a; 11 | a = a + b; 12 | b = temp; 13 | num--; 14 | } 15 | 16 | self.postMessage(b); 17 | } 18 | -------------------------------------------------------------------------------- /web-workers/fibonacci-worker/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |