Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. //Try writing a simple progress bar function in the callback style. Your function should take three callbacks,
  2. //onStart, onProgress, and onEnd as arguments. When you call the function it should call the onStart callback,
  3. //then loop from 1 to 100, using console.log to print each value. Every 10 items it counts it should call the
  4. //onProgress callback, providing how far along it is as an argument. Finally it should call the onEnd callback.
  5.  
  6. function progressBar(callback1, callback2, callback3){
  7. callback1();
  8. for(var i =0; i<=100; i++){
  9. console.log(i);
  10. callback2(i);
  11. }
  12. callback3();
  13. }
  14.  
  15. var onStart = function(){
  16. console.log("start");
  17. }
  18.  
  19. var onEnd = function(){
  20. console.log("end");
  21. }
  22.  
  23. var onProgress = function(num){
  24. if(num%10 === 0 && num!= 0){
  25. console.log("counted ten more, till "+num);
  26. }
  27.  
  28. }
  29.  
  30. progressBar(onStart, onProgress, onEnd);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement