Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function solve() {
  2. return function (selector, count) {
  3. if(typeof selector === 'undefined' || selector === null || typeof selector !== 'string'){
  4. throw Error('Invalid or missing selector!');
  5. }
  6.  
  7. if (isNaN(count) || count < 1) {
  8. throw Error('Count is not a valid number!');
  9. }
  10.  
  11. var $ul = $('<ul />').addClass('items-list');
  12. var $selected = $(selector);
  13.  
  14. if ($selected.length !== 0) {
  15. for (var i = 0; i < count; i += 1) {
  16. var $li = $('<li>')
  17. .addClass('list-item')
  18. .text('List item #' + i)
  19. .appendTo($ul);
  20. }
  21.  
  22. $selected.append($ul);
  23. }
  24. };
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement