Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wbamberg committed Sep 13, 2023
1 parent ff16310 commit 4a7140f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions files/en-us/web/api/web_workers_api/using_web_workers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,20 @@ Workers are mainly useful for allowing your code to perform processor-intensive
The following JavaScript code is stored in the "fibonacci.js" file referenced by the HTML in the next section.
```js
self.onmessage = function (event) {
self.onmessage = (event) => {
const userNum = Number(event.data);
self.postMessage(fibonacci(userNum));
};

function fibonacci(n) {
return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
function fibonacci(num) {
let a = 1;
let b = 0;
while (num > 0) {
[a, b] = [a + b, a];
num--;
}

return b;
}
```
Expand Down

0 comments on commit 4a7140f

Please sign in to comment.