OneCompiler

Pls check my solution of integers sum Question

NOT RUNNING

var readline = require('readline');

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

function processSum(number) {
// Insert code to do whatever with sum here.
console.log('The sum is', number);
}

rl.question('Enter a number: ', function (x) {
rl.question('Enter another number: ', function (y) {
var sum = parseFloat(x) + parseFloat(y);

    processSum(sum)

    rl.close();
});

});

1 Answer

3 years ago by

@Anjali Chauhan

Please find a working solution here https://onecompiler.com/nodejs/3y2c44kc3

var readline = require('readline');

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

function processSum(number) {
// Insert code to do whatever with sum here.
console.log('The sum is', number);
}

rl.once('line', (x) => {
  console.log('first number' + x);
  
  rl.once('line', (y) => {
    console.log('second number' + y);
    
    var sum = parseFloat(x) + parseFloat(y);
    processSum(sum);
    
  });
});
3 years ago by OneCompiler