Skip to content

Instantly share code, notes, and snippets.

@ZacharyDinerstein
Created January 22, 2014 15:04
Show Gist options
  • Select an option

  • Save ZacharyDinerstein/8560219 to your computer and use it in GitHub Desktop.

Select an option

Save ZacharyDinerstein/8560219 to your computer and use it in GitHub Desktop.
//========================================PART 2 (BONUS)===========================================
//=======================================Favorite Things===================================
var my_array = ["Talking Heads", "Sonic Youth", "Television", "Tom Waits", "The Woes", "They Might Be Giants", "Sleater-Kinney", "Wilco", "Stereolab", "The Woes", "Reggie Watts", "Radiohead", "Bjork", "Ted Leo", "Bob Dylan"];
var num = 1; //Set 'num' to 1. Will Allow us to count..
//..our first favorite band below.
var num_string = num.toString(); //The following steps converts 'num' into..
var string_array = num_string.split(""); //..an array which holds each integer of..
var new_num_array = []; //..'num' as a seperate index. The result..
//..is stored in 'new_num_array'.
string_array.forEach(function(string){
var number = parseInt(string);
new_num_array.push(number);
});
//Stores the last integer from our..
//..original number in 'end_didget'.
var end_didget = new_num_array[new_num_array.length - 1];
//Iterates through my_array, sending an..
//..out put to the console for each value..
//..in the array. Sets the tense of the..
//..output based on with loop of the..
//..itteration we're in.. (first, second,..
//..third, etc...).
my_array.forEach(function(band){
if (end_didget === 1) {
console.log("My "+ num + "st favorite band is " + band);
} else if (end_didget === 2){
console.log("My "+ num + "nd favorite band is " + band);
} else if (end_didget === 3){
console.log("My "+ num + "rd favorite band is " + band);
} else if (end_didget === 4 || 5 || 6 || 7 || 8 || 9 || 0 || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 19){
console.log("My "+ num + "th favorite band is " + band);
}
num++;
end_didget++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment