Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Try writing a simple progress bar function in the callback style. Your function should take three callbacks,
- //onStart, onProgress, and onEnd as arguments. When you call the function it should call the onStart callback,
- //then loop from 1 to 100, using console.log to print each value. Every 10 items it counts it should call the
- //onProgress callback, providing how far along it is as an argument. Finally it should call the onEnd callback.
- function progressBar(callback1, callback2, callback3){
- callback1();
- for(var i =0; i<=100; i++){
- console.log(i);
- callback2(i);
- }
- callback3();
- }
- var onStart = function(){
- console.log("start");
- }
- var onEnd = function(){
- console.log("end");
- }
- var onProgress = function(num){
- if(num%10 === 0 && num!= 0){
- console.log("counted ten more, till "+num);
- }
- }
- progressBar(onStart, onProgress, onEnd);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement