Pure Programmer
Blue Matrix


Cluster Map

Selection

L1

This page is under construction. Please come back later.

Selection1.js
#!/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...
Selection2.js
#!/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...
Selection3.js
#!/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...
Selection4.js
#!/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
Selection5.js
#!/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
javascript

Questions

Projects

More ★'s indicate higher difficulty level.

References