Problem 3. vendingmachine.js

/*
Vending machine
Rahul runs a shop that sells soft drinks.
He wants help in building a vending machine that asks the customer's name and choice of soft
drink.
He then wants the machine to greet the user and display their order. Write a program that
Rahul can use for the vending machine.

Input
First line contains the customer's name

Second line contains the choice of the customer

Output
Two lines in the following format.

Hello <customer name> !!!
You ordered <customer order>.
Example
Input:

Rajesh
Coca cola
Output:

Hello Rajesh !!!
You ordered Coca cola.
*/
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(); // Rajesh
let customerOrder = readLine(); // Coca cola
console.log("Hello " + customerName + " !!!"); // Hello Rajesh !!!
console.log("You ordered " + customerOrder + "."); //You ordered Coca cola.

Terminal:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node vendingmachine.js <input.txt Hello Rajesh !!! You ordered Coca cola.



 

Comments

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js

Problem 16. chocolatebills.js