U
U
Umid2017-01-19 21:19:01
JavaScript
Umid, 2017-01-19 21:19:01

How to interact with the console in NodeJs?

Interested in the interaction of the vanilla node with the console.
For example, make a console calculator on nodejs, without any additional. plugins.
Is it possible to?
Googling found only the implementation through plugins.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vetsmen, 2017-01-20
@DarCKoder

process.stdin, google and look deeper

S
Sergey delphinpro, 2017-07-26
@good_br

$a=4;
$b=10;
$z= $a*$b;

if ($a && $b > -1) { 
    echo $a-$b;
}
elseif ($a && $b < 0) {
    echo $a * $b;
}    
elseif ($z < -1) {
    echo $a+$b;
}

20170726-054354.png

V
Viktor, 2017-07-26
@TexElless

Parentheses are of course correct, but the "magic" is not in them, the initial problem is that there are extra semicolons.
The parser understood your version as:

$a=4;
$b=10;
$z= $a*$b;
if ($a && $b > -1) {
  echo $a-$b;
} elseif ($a && $b < 0) {};
echo $a * $b; // уже выполнится без условия
elseif ($z < -1) {}; // соответственно уже вообще не относится к предыдущему if'у
echo $a+$b;

Therefore, brackets should be put, with them it is clearer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question