User prompt not working

In This code,

const prompt = require("prompt-sync")();
const readline = require("readline-sync");

let rows = parseInt(readline.question("Enter The row: "));
let Columns = parseInt(readline.question("Enter The columns: "));
let arr = [];

console.log("Enter The matrix: ");

for (let i = 0; i < rows; i++) {
  arr.push([]);
  for (let j = 0; j < Columns; j++) {
    arr[i].push(parseInt(readline.question()));
  }
}
console.log(arr);

I’m not able to take the user input correctly. It is not terminating after the for loop. Can someone help me please?

I don’t know exactly what you want to do, but it’s line:

arr[i].push(parseInt(readline.question())); 

It may be that it is incorrect and that what you want to do is add the rows with each push:

arr[i].push(rows); 

And answering your question. The for() never ends because for each iteration it is slowed down for you to make an entry, that is due to the existence of parseInt(readline.question()) inside the for()

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.