Skip to content

Clarification #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions exercises/baby_steps/problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@ Write a program that accepts one or more numbers as command-line arguments and p
----------------------------------------------------------------------
## HINTS

You can access command-line arguments via the global `process` object. The `process` object has an `argv` property which is an array containing the complete command-line. i.e. `process.argv`.
You can access command-line arguments via the global `process` object. The `process` object has an `argv` property which is an array containing the complete command-line, i.e. `process.argv`.

To get started, write a program that simply contains:

```js
console.log(process.argv)
```

Run it with `node program.js` and some numbers as arguments. e.g:
Run it with `node program.js` and provide some numbers as arguments, e.g.:

```sh
$ node program.js 1 2 3
```

In which case the output would be an array looking something like:
The output would be an array looking something like:

```js
[ 'node', '/path/to/your/program.js', '1', '2', '3' ]
```

You'll need to think about how to loop through the number arguments so you can output just their sum. The first element of the process.argv array is always 'node', and the second element is always the path to your program.js file, so you need to start at the 3rd element (index 2), adding each item to the total until you reach the end of the array.
Think about how to loop through the number arguments so you can output only their sum. The first element of the `process.argv` array is always 'node', and the second element is always the path to your program.js file. You'll need to start at the 3rd element (index 2), adding each element to the total sum until you reach the end of the array.

Also be aware that all elements of `process.argv` are strings and you may need to *coerce* them into numbers. You can do this by prefixing the property with `+` or passing it to `Number()`. e.g. `+process.argv[2]` or `Number(process.argv[2])`.
Try to remember what kind of statement JavaScript uses to hold on to values. What scope such a container would need? Which value would it initially be assigned to?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more confusing IMO


{appname} will be supplying arguments to your program when you run `{appname} verify program.js` so you don't need to supply them yourself. To test your program without verifying it, you can invoke it with `{appname} run program.js`. When you use `run`, you are invoking the test environment that {appname} sets up for each exercise.
Also be aware that all elements of `process.argv` are strings and they may need to be *coerced* into numbers in order to be added. You can do this by prefixing the property with `+` or passing it to `Number()`. e.g. `+process.argv[2]` or `Number(process.argv[2])`.

{appname} will supply arguments to your program when you run `{appname} verify program.js`, so there is no need to supply them yourself. To test your program without verifying it, you can invoke it with `{appname} run program.js`. When you use `run`, you are invoking the test environment that {appname} sets up for each exercise.

----------------------------------------------------------------------