I'm having a hard time undestanding how to use the readline library from NodeJS to read two different strings for a Kattis challenge.
See, in their documentation there's the following example:
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', (line) => {
var nums = line.split(' ');
var a = parseInt(nums[0]);
var b = parseInt(nums[1]);
/*Solve the test case and output the answer*/
});
I need to read two strings and then manipulate them. I've already tried doing:
const readline = require('readline');
var string1 = '';
var string2 = '';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', (line) => {
var string1 = line;
});
rl.on('line', (line) => {
var string2 = line;
});
//manipulating strings...
and even:
const readline = require('readline');
var string1 = '';
var string2 = '';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('', (answer) => {
var string1 = answer;
});
rl.question('', (line) => {
var string2 = answer;
});
//manipulating strings...
But I keep getting a Run time error. What am I doing wrong, exactly?