The following code prints a message to the console

console.log("Hi");
Hi

If you type this in a normal JavaScript file though, this message would not show on the webpage. Instead, you have to go to Inspect Element (Ctrl + Shift + I in Chrome, using Windows), and go to the Console tab to view the message.

Functions

Since I can't run the following code below in Jupyter Notebook, I'll attach a screenshot of running the output in terminal.

The reason this can't be run Jupyter Notebook (although I'll have to do more research about Jupyter Notebook to fully understand) is that Jupyter Notebook can't take input for JavaScript using prompt or readline. Maybe there's another way to have Jupyter Notebook take in input, but that'll take me a long time to research.

As shown below, I made a calculator with the code below. I created the functions add, subtract, multiply, and divide.

const prompt = require('prompt-sync')();

var total = prompt('1st number? ');
var num2 = prompt('2nd number? ');
var operation = prompt('Add/subtract/multiply/divide? Type: +/-/*, or /: ');


function add(total, num2) {
    return Number(total) + Number(num2);
}

function subtract(total, num2) {
    return Number(total) - Number(num2);
}

function multiply(total, num2) {
    return Number(total) * Number(num2);
}

function divide(total, num2) {
    return Number(total) / Number(num2);
}

while (num2 != "end") {
    if (operation == "+") {
        total = add(total, num2);
    }
    
    if (operation == "-") {
        total = subtract(total, num2);
    }
    
    if (operation == "*") {
        total = multiply(total, num2);
    }
    
    if (operation == "/") {
        total = divide(total, num2);
    }

    console.log("Your result is " + total);

    num2 = prompt('2nd number? ');
    if (num2 == "end") {
        break; 
    }
    operation = prompt('Add/subtract/multiply/divide? Type: +/-/*, or /: ');
}



console.log("Your result is " + total);

Running the code in terminal, here is the output.

Array and objects

function Fruits(name, taste) {
    this.name = name;
    this.taste = taste;
}

var fruits = [
    new Fruits("apple", "sweet, sour"),
    new Fruits("mango", "sweet")
];

function Combine(fruits) {
    this.fruits = fruits;
    this.combine = [];
    this.fruits.forEach(fruit => {this.combine.push(fruit);});
}

printFruits = new Combine(fruits);

console.log(printFruits.combine);
[ Fruits { name: 'apple', taste: 'sweet, sour' },
  Fruits { name: 'mango', taste: 'sweet' } ]