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

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js

Problem 16. chocolatebills.js