Problem 2. printname.js
/*
Print name
Read a name as input and print "Hello {name}"
Input
One line containing a string, i.e. name
Output
Hello {name}
Example
Input: Ravi
Output: Hello Ravi
*/
let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');
function readLine() {
idx++;
return data[idx - 1].trim();
}
//.......................................................................................
let customerName = readLine(); // Ravi
console.log("Hello " + customerName); // Hello Ravi
Terminal:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node printname.js <input.txt
Hello Ravi
Comments
Post a Comment