Created
April 30, 2015 16:20
-
-
Save rubadeau/2a3c6f1d92c11fc9ea4f to your computer and use it in GitHub Desktop.
JS Record Player - Code Review
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
| $(document).ready(function() { | |
| $(".record").on("click", function() { | |
| playSymphony(); | |
| }); | |
| var playTrack = function(track) { | |
| track.play(); | |
| } | |
| //Naming: Does it pause one track or all tracks? | |
| var pauseTrack = function(tracks) { | |
| tracks.each(function(index, sample) { | |
| (tracks[index]).pause();//nice use of the higher order function looping over each track | |
| }); | |
| }; | |
| var playSymphony = function() { | |
| $('#stopwatch').timer('resume'); | |
| if ($(".record").hasClass('rotate')) { | |
| $('#stopwatch').timer('pause'); | |
| pauseTrack( $("audio") ); | |
| } | |
| //Clould you have used else here to improve readability? | |
| if (!($(".record").hasClass('rotate'))) { | |
| playTrack($("audio").get(0));//nice grabing all the audio elements and selecting them with .get() | |
| setTimeout(function(){ | |
| ($("audio").get(0)).pause(); | |
| }, 3100) | |
| setTimeout(function(){ | |
| playTrack($("audio").get(1)); | |
| playTrack($("audio").get(2)); | |
| }, 3000); | |
| } | |
| $(".record").toggleClass('rotate'); | |
| }; | |
| //The toggleClass outside of your conditional statement was good use of the negative case example | |
| });//What happens when you stop the symphony before 3 seconds? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment