Problem 9. eligibility.js ( if/else condition is introduced)
/*Question
Given a person's age, determine if they are eligible for travel concession.
A person is allowed concession if they are more than 60 years old.
Input:
one line containing an integer, denoting the age of the person.
output:
one line containing a string. Eligible if the person is allowed for concession and Not eligible otherwise.
Example:
Input
38
Expected Outcome:
Not eligible
Algorithm:
1. Read the age of the person.
2. Check if the age is greater than 60, then
3. Display Eligible
4. else display Not eligible
*/
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 age = parseInt(readLine()); // 38
if (age > 60) {
console.log("Eligible"); // 38 > 60 false go to the else part
}
else {
console.log("Not eligible");
}
Terminal:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node eligibility.js <input.txt
Not eligible
Comments
Post a Comment