# How to display the result of a Javascript cell?

**URL:** <https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662>\
**Category:** Notebook\
**Created:** [July 28, 2023, 1:38am UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662 "2023-07-28T01:38:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![slimUp](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@slimUp](https://discourse.jupyter.org/u/slimUp)\
**Post date:** [July 28, 2023, 1:38am UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/1 "2023-07-28T01:38:28Z")

</div>

## Hi, I have this JS code in a code cell and when it runs nothing happens…

```auto
%%js
// Put a zero in for the unknown value
let n1 = 1;
let d1 = 2;
let n2 = 0;
let d2 = 16;

if (n2 === 0) {
  let answer = (d2 * n1) / d1;
  console.log("n2 =", answer);
}

if (d2 === 0) {
  let answer = (n2 * d1) / n1;
  console.log("d2 =", answer);
}

```

## I’m trying to translate that python code that work:

```auto
# Put a zero in for the unknown value
n1 = 1
d1 = 2
n2 = 0
d2 = 16

if n2==0:
    answer = d2 * n1 / d1
    print("n2 = ", answer)
    
if d2==0:
    answer = n2 * d1 / n1
    print("d2 = ", answer)

```

thanks for your help 🙂

---

<div class="post-metadata">

**Author:** ![spookster](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/spookster/32/8939_2.png) [@spookster](https://discourse.jupyter.org/u/spookster)\
**Post date:** [July 28, 2023, 7:49am UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/2 "2023-07-28T07:49:36Z")

</div>

The code just runs in your browser, so the output is in the browser console.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/4/4ab6ba47ae0b618a5b393498024df63a3d9c16cc.png)

If you want the output to be inside a notebook you should install nodejs and a javascript kernel.  
I use [tslab](https://github.com/yunabe/tslab) but since jupyterlab 4 the syntax highlighting does not work anymore.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/0/0a96721e83dbcb19593a6b315ea1b6ae01a19e94.png)

---

<div class="post-metadata">

**Author:** ![slimUp](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@slimUp](https://discourse.jupyter.org/u/slimUp)\
**Post date:** [July 29, 2023, 4:49pm UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/3 "2023-07-29T16:49:33Z")

</div>

Hey @spookster! thank you so much for your answer!  
I see, yes I’m getting the correct output in the console.  
Now I tried to install tslab following the recommendations from the Github link:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/6/654a28c71a418e4dbcf3768cfd5c0da1f99548c0.png)  
(I have Python 3.10.6 and node v20.4.0 installed)  
but it still doesn’t work:  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/d/d20ebfee2073f5d713558e7940695365f38d303c.png)  
I’m using Jupyter Notebook 7.0  
Thank you 🙂

---

<div class="post-metadata">

**Author:** ![spookster](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/spookster/32/8939_2.png) [@spookster](https://discourse.jupyter.org/u/spookster)\
**Post date:** [July 29, 2023, 4:57pm UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/4 "2023-07-29T16:57:07Z")

</div>

the syntax highlighting suggest you are still on the Python kernel.

you need to create a notebook using the javascript kernel or switch the kernel in the top right corner to the javascript kernel.

---

<div class="post-metadata">

**Author:** ![slimUp](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@slimUp](https://discourse.jupyter.org/u/slimUp)\
**Post date:** [July 29, 2023, 6:44pm UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/5 "2023-07-29T18:44:04Z")

</div>

@spookster it works! (after restarting the server)  
thanks for your help I really appreciate it! have a good one 🙂

---

<div class="post-metadata">

**Author:** ![slimUp](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@slimUp](https://discourse.jupyter.org/u/slimUp)\
**Post date:** [July 30, 2023, 11:01pm UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/6 "2023-07-30T23:01:35Z")

</div>

@spookster I’m getting this error when restarting the server:

![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/5/5610d29925fc4047ce56e32d4bce4bdb56721061.png)

running the Python 3 (ipykernel) kernel works fine… any idea?

finding this post: [Kernel Error: Failed to start a kernel - #3 by Rose\_Zhang](https://discourse.jupyter.org/t/kernel-error-failed-to-start-a-kernel/8690/3)  
it looks like it works when I start the server from the command line but not from the launcher… (on linux mint with jupyter notebook 7.0)

---

<div class="post-metadata">

**Author:** ![spookster](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/spookster/32/8939_2.png) [@spookster](https://discourse.jupyter.org/u/spookster)\
**Post date:** [July 31, 2023, 7:46am UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/7 "2023-07-31T07:46:59Z")

</div>

add the the folder with npm binaries to your PATH environment variable.

---

<div class="post-metadata">

**Author:** ![slimUp](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@slimUp](https://discourse.jupyter.org/u/slimUp)\
**Post date:** [August 3, 2023, 12:40am UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/8 "2023-08-03T00:40:11Z")

</div>

Hi @spookster, I have tried different stackoverflow solutions like

```auto
export PATH=$PATH:/home/user_name/.nvm/versions/node/v20.4.0/bin

```

or

![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/5/51b8f5591c106c381782b5a8c803399fa680e368.png)

\*\* with the correct path I get from `which node` \*\*

but nothing worked so far…  
Would you mind telling me the commands?  
Thank you

---

<div class="post-metadata">

**Author:** ![spookster](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/spookster/32/8939_2.png) [@spookster](https://discourse.jupyter.org/u/spookster)\
**Post date:** [August 3, 2023, 11:58am UTC](https://discourse.jupyter.org/t/how-to-display-the-result-of-a-javascript-cell/20662/9 "2023-08-03T11:58:12Z")

</div>

this should normally work but I don’t know why it’s not working for you.

you can put the complete path into the `.local/share/jupyter/kernels/jslab/kernel.json` (and the tslab kernel too while you are at it).

just change

```auto
{"argv": ["tslab", "kernel", "--config-path", "{connection_file}", "--js"], "display_name": "JavaScript", "language": "javascript"}

```

to something like this:

```auto
{"argv": ["/path/to/your/tslab/executable/from/which/tslab", "kernel", "--config-path", "{connection_file}", "--js"], "display_name": "JavaScript", "language": "javascript"}

```
