AroliS

how to create a progress bar with slashes in node js

Feb 15th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. all credits goes to me, AroliS^.
  3. You are not allowed to publish this as yours,
  4. however you can use it as you want.
  5. */  
  6.  
  7.   function createBar( percent )
  8.     {
  9.         let num = parseInt( percent / 10, 10 )
  10.             , slash = '//////////' //progress bar
  11.             , decreasing = slash.length - num // decreasing means the number of percent that it will increased.
  12.             , addslash = ''; //adding slashes
  13.  
  14.             for( var i = 0; i < num; i++ )
  15.             {
  16.                 addslash += '/'; //we're looping the percent that will be added in slashes
  17.             }
  18.              
  19.         return addslash == '' ? '['+ slash.slice( 0, decreasing ) + ']' : `[\` ${addslash} \``+ slash.slice( 0, decreasing ) + `]`;  
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment