Advertisement
schrodervictor

Victor Schröder's solution for JavaScript Challenge

Jun 6th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Solutions for http://tutorialzine.com/2014/05/javascript-challenge-make-me-blue/#comment-154928 */
  2. /* By Victor Schröder - linkedin.com/in/schrodervictor/ */
  3.  
  4. //1. IDs are easy
  5. $('#me').blue();
  6.  
  7. //2. So are classes..
  8. $('.wants-to-be-blue').blue();
  9.  
  10. //3. The unordered list
  11. $('ul li:nth-child(4)').blue();
  12.  
  13. //4. Treacherous HTML ahead!
  14. $('#make-me-blue, ' +
  15.   'section:first div:nth-of-type(3), ' +
  16.   'section:last p:first > span, ' +
  17.   'section:last p:nth-of-type(3) > span > i:nth-of-type(2), ' +
  18.   'section:last > div > div').blue();
  19.  
  20. // 5. Mind the order!
  21. for (i=1;i<=9;i++) {
  22.     $('div:contains("' + i + '")').blue();
  23. }
  24.  
  25. // 6. Beware of the bombs!
  26. $('div:not(".bomb")').blue();
  27.  
  28. // 7. You’ve got enemies!
  29. setTimeout(function() {
  30.     $('section div').blue();
  31. }, 1100);
  32.  
  33. //8. Speed is everything
  34. $('button').trigger('click');
  35. $('div').blue();
  36.  
  37. //9. Randomization
  38. $('#' + $('#map').text().split(' ').join(',#')).blue();
  39.  
  40. //10. Boss fight
  41. var delay = 60,
  42.     position = 0,
  43.     divs = $('div');
  44.  
  45. setTimeout(makeBlue, delay);
  46.  
  47. function makeBlue(){
  48.     divs.eq(position).blue();
  49.     divs.eq(position + 5).blue();
  50.     setTimeout(function(){
  51.         position++;
  52.         if(position >= divs.length){
  53.             position = 0;
  54.         }
  55.         setTimeout(makeBlue, 500);
  56.     }, 100);
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement