Selection

This page is under construction. Please come back later.
#!/usr/bin/env node;
const main = async () => {
console.log("Start...");
if (process.argv.length != 4) {
console.log("You need at least two command line arguments!");
}
console.log("Finish...");
}
main().catch( e => { console.error(e) } );
Output
$ node Selection1.js abc
Start...
You need at least two command line arguments!
Finish...
$ node Selection1.js abc 123
Start...
Finish...
#!/usr/bin/env node;
const Utils = require('./Utils');
const main = async () => {
const x = Utils.stoiWithDefault(process.argv[2], 0);
console.log("Start...");
if (x > 10) {
console.log("Greater than 10");
} else {
console.log("Less than or equal to 10");
}
console.log("Finish...");
}
main().catch( e => { console.error(e) } );
Output
$ node Selection2.js 8
Start...
Less than or equal to 10
Finish...
$ node Selection2.js 12
Start...
Greater than 10
Finish...
#!/usr/bin/env node;
const Utils = require('./Utils');
const main = async () => {
const x = Utils.stoiWithDefault(process.argv[2], 0);
console.log("Start...");
if (x > 1000) {
console.log("Greater than 1000");
} else if (x > 100) {
console.log("Greater than 100 but less than or equal to 1000");
} else {
console.log("Less than or equal to 100");
}
console.log("Finish...");
}
main().catch( e => { console.error(e) } );
Output
$ node Selection3.js 12
Start...
Less than or equal to 100
Finish...
$ node Selection3.js 120
Start...
Greater than 100 but less than or equal to 1000
Finish...
$ node Selection3.js 1200
Start...
Greater than 1000
Finish...
#!/usr/bin/env node;
const Utils = require('./Utils');
const main = async () => {
const x = Utils.stoiWithDefault(process.argv[2], 0);
switch (x) {
case 1:
console.log("One");
break;
case 2:
console.log("Two");
break;
case 3:
case 4:
console.log("Three or Four");
break;
default:
console.log("Just don't know!");
break;
}
}
main().catch( e => { console.error(e) } );
Output
$ node Selection4.js 0
Just don't know!
$ node Selection4.js 1
One
$ node Selection4.js 2
Two
$ node Selection4.js 3
Three or Four
$ node Selection4.js 4
Three or Four
#!/usr/bin/env node;
const Utils = require('./Utils');
const main = async () => {
let x = Utils.uniAt(process.argv[2], 0);
x = x.toLowerCase();
switch (x) {
case "a":
case "e":
case "i":
case "o":
case "u":
console.log(Utils.format("{0:c} is a vowel", x.codePointAt(0)));
break;
case "y":
console.log("y is sometimes a vowel");
break;
default:
console.log(Utils.format("{0:c} is a consonant", x.codePointAt(0)));
break;
}
}
main().catch( e => { console.error(e) } );
Output
$ node Selection5.js a
a is a vowel
$ node Selection5.js g
g is a consonant
$ node Selection5.js I
i is a vowel
$ node Selection5.js T
t is a consonant
$ node Selection5.js y
y is sometimes a vowel
Questions
- {{Who's on first?}}
- {{Who's on second?}}
- {{Who's on third?}}
Projects
More ★'s indicate higher difficulty level.
- FICA Taxes (Revisited)
- FICA Taxes (Empoyee and Employer)
- Football Passer Rating (NFL and NCAA)
- Income Tax (Single Taxpayer)
- Income Tax
- Pythagorean Theorem
- Retirement Calculator
References
- [[JavaScript Language Reference]], Mozilla Developer Network
- [[Mozilla Developer Network]]
- Download [[node.js]]
- [[w3schools.com]]
Pure Programmer


