5 - JavaScript Scripting

BASH and other scripting languages are fantastic in the shell and for quick or OS-specific scripts. But what if you want something a little more powerful and cross-platform?

What are we learning?

In this lesson we will:

Review of JavaScript

We've covered a lot already - let's take a moment to remind ourselves about the syntax and flow of JavaScript.

The grade 11 course covers the following:

The Lesson

Browsers have the brains of JavaScript already "installed". The interpreter and CLI are available throught the dev tools. (Try CTRL+SHIFT+J or CTRL+SHIFT+I or F12)

The Chrome version of that JS Interpreter has since been released as a standalone language and heavily modified for various use-cases. It works a lot like other scripting languages and has some significant differences with the browser version (no built-in prompt() as an example)

It is called NodeJS and it does not come pre-installed with Linux.

Let's Install NodeJS

From your terminal (CLI):  sudo apt update && sudo apt install nodejs npm

That line will update the software repositories and then install the NodeJS software and the Node Package Manager. It might take a while - it's not small.

Our First NodeJS Script

Inside your Home folder (~) create a new folder for our work:  mkdir js

Go into the folder (cd js) and make a new file called treats.js - we're going to write the dog treats program one last time - in JavaScript!

Practice (Shake off the Rust)

Feel free to work together / with a partner on these. The goal is to problem solve while reviewing previous skills. You have today, tomorrow, and Thursday to work on these. If there is a snow day, we will lose that day.

Were those too easy for you? Try these competition problems.