Skip to content

Instantly share code, notes, and snippets.

@MariaSzubski
Last active July 21, 2016 21:03
Show Gist options
  • Select an option

  • Save MariaSzubski/9371eb0beae556b107d3 to your computer and use it in GitHub Desktop.

Select an option

Save MariaSzubski/9371eb0beae556b107d3 to your computer and use it in GitHub Desktop.
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] + '.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment