Project: A Movie-Night Snack Calculator

At the very start of this course, you read that you’d end up with a tiny movie-night snack calculator running on your own computer. It’s time to build it! You’ve already done each step once: open your course folder, create a script, print a message, show a calculation, save, run, and fix a mistake.

This project puts those steps together in one new file. You’ll write two short lines: one that announces your movie night and one that works out what the popcorn costs. Then you’ll change the numbers and check the answer yourself. Plan on about twenty-five minutes, with VS Code open next to this page.

There’s no automatic checker for this one. The project runs locally, which simply means on your own computer, from a file you own. You decide what the program should print, and the terminal shows you whether it does. That makes you the checker. Checking your program’s output is the skill this course set out to give you.

Reopen Your Course Folder

Start VS Code. It usually reopens the last folder you worked in, so look for js-course at the top of the Explorer panel. If you see a different folder or none at all, choose File → Open Folder and pick js-course, just as you did when you first set it up.

Then open a terminal with Terminal → New Terminal and read the prompt before you type anything. It should end in js-course. If it does, then any node scratch/... command you type will find files in your scratch folder.

Start With One Movie-Night Message

In the Explorer panel, click the scratch folder once, click the New File icon, type snacks.js, and press Enter. Check the spelling on the tab that opens, since you’ll type this name each time you run the script.

Your calculator starts the same way your first script did, with one line that prints a message. Type it into the new file.

Language: JavaScript Filename: scratch/snacks.js
console.log("Movie night starts at eight!");

Save with Ctrl+S, or Cmd+S on macOS, and check that the dot on the tab has turned back into an ×. Then run your new script.

Language: Shell
$ node scratch/snacks.js
Movie night starts at eight!

There it is, your project’s first output! If Node answers with Cannot find module instead, compare the name in your command with the name in the Explorer panel.

If they match but your prompt doesn’t end in js-course, the terminal is in the wrong folder. Make sure the Explorer shows js-course at the top, using File → Open Folder if it doesn’t. Close the misplaced terminal with the trash can icon, choose Terminal → New Terminal, check that the new prompt ends in js-course, and run node scratch/snacks.js again.

Now make the message yours. Change the text between the quotes to the movie you’d pick, the time it starts, or who’s coming over. Keep the quotes, the parentheses, and the semicolon as they are. Here’s one possible version.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.