R
R
ramazan222018-06-05 10:49:57
JavaScript
ramazan22, 2018-06-05 10:49:57

Present code in Node?

I solved the problem (calculate the area of ​​an inscribed circle). Got this code

var a = 6;
 var b = 8;
 console.log((3.14 * Math.pow((a + b - (Math.sqrt(Math.pow(a,2) +Math.pow(b,2) ).toFixed(2)))/2,2)).toFixed(2));

Output conditions -
Example
> node task.js 6 8
> 12.56
The first argument is in process.argv[1]
Question - how do I add this process.argv[1] to the code now?
var a = process.argv[1]; varb = process.argv[2]; - tried. Not right

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-06-05
@ramazan22

And why didn't you turn to the documentation ? - it would immediately become clear that the passed arguments begin with an index equal to 2. And not 1.
And of course, you forgot that the command line arguments are of type string, and you use them as numbers - the result will be completely different from you expect. We have to transform.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question