Created
January 9, 2024 01:11
-
-
Save EteimZ/27ec105238468ce2eec8ea4cf16ff375 to your computer and use it in GitHub Desktop.
A simple command line application behaving like a USSD application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import the readline module to get user input | |
readline = require('node:readline') | |
class BankUSSD { | |
main(){ | |
// Define the variable that will be used to get user input | |
const userInput = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
console.log("Access Bank") | |
console.log("1>Check balance") | |
console.log("2>Transfer") | |
console.log("3>Airtime") | |
console.log("4>Buy Data") | |
console.log("\n\n") | |
// Prompt user to select their option | |
userInput.question(`Please an option:`, option => { | |
this.handleInput(option); | |
input.close(); | |
}); | |
} | |
// method to handle user input | |
handleInput(option){ | |
if (option == 1){ | |
console.log("You selected option 1") | |
} else if (option == 2) { | |
console.log("You selected option 2") | |
} else if (option == 3) { | |
console.log("You selected option 3") | |
} else if (option == 4) { | |
console.log("You selected option 4") | |
} else { | |
console.log("Unknown option") | |
} | |
} | |
} | |
// Create an instance of the BankUSSD class | |
let ussd = new BankUSSD() | |
// Call the main method | |
ussd.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment