MariaSzubski
8/12/2015 - 2:38 PM

Append suffixes in an ordered list.

Append suffixes in an ordered list.

// ------------------------------------- Create an array for the ordered list
var podcasts = [
	'99% Invisible',
	'The Light Bulb',
	'Planet Money',
	'Radiolab',
	'TED Radio Hour',
	'StarTalk Radio',
	'The Vergecast',
	'Song Exploder',
	'Freakonomics Radio',
	'Invisibilia',
	'Snap Judgment',
	'The Nerdist',
	'This American Life',
	'Welcome to Nightvale',
	'Comedy Bang Bang',
	'Motley Fool Answers',
	'StartUp Podcast',
	'Studio 360',
	'Stuff Mom Never Told You',
	'Money Talking',
	"What's Tech",
	"Let's Make Mistakes",
	'Note To Self',
	"What's the Point"
];

// ------------------------------------- Loop through the array and attach the correct number suffixes
var suffix, num;
for (var i = 0; i < podcasts.length; i++) {
	num = i + 1;
	if ( num >= 11 && num <= 13 ){
		suffix = 'th';
	} else {
		switch (num % 10){
			case 1:
				suffix = 'st';
				break;
			case 2:
				suffix = 'nd';
				break;
			case 3:
				suffix = 'rd';
				break;
			default:
				suffix = 'th';
				break;
		}
	}
	console.log('My '+ num + suffix + ' choice is ' + podcasts[i] + '.');
}