Created
January 22, 2014 15:04
-
-
Save ZacharyDinerstein/8560219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //========================================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