This site is a preview of the curriculum for our Summer 2018 bootcamp in Burlington, Vermont. As we continue our preparation, courses and lessons will appear and disappear; we will rename, rearrange, clarify, and obfuscate as needed... Please consider this a work in progress and keep checking in.


 Learn to Code with JavaScript:
Argv


 Slides

ARGV

In every NodeJS program, there is a magic array named argv.

It contains the command line arguments to the program.

If the user types:

node hello.js Alice Bob

then process.argv contains:

["Alice", "Bob"]

Why ARGV?

ARGV is a historical name. It means "Argument Vector" and has been around since the early 1970s.

Command-Line Hello

Write a new program called hi.js that contains:

console.log("Hi, " + process.argv[0])

and run it a few times, e.g.

node hi.js Alice
node hi.js Bob

LAB: Hello, Everyone!

Change hi.js to say hi to every one of its command line arguments.

For instance:

node hi.js Alice Bob Charlie
Hi, Alice!
Hi, Bob!
Hi, Charlie!

LAB: Add

Write a program named add.js that adds all of its command line arguments together.

e.g.

node add.js 1 2 3 4
10

Hint: Do you remember how to cleanly convert a string to a number?


Suggested Projects



Comments

comments powered by Disqus