Stan08

1. Gift Shop

Mar 10th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function solution() {
  2.  
  3. let isMatch = true;
  4. $('button').on('click', function(){
  5.  
  6. let div = $('<div>');
  7. div.addClass('gift');
  8.  
  9. let img = $('<img>');
  10. img.attr('src','gift.png');
  11. div.append(img);
  12.  
  13. let inputh2 = $('#toyType').val();
  14. $('#toyType').val('')
  15. if(inputh2==''){isMatch=false;}
  16. let h2 = $('<h2>');
  17. h2.text(inputh2);
  18.  
  19. let inputp = $('#toyDescription').val();
  20. $('#toyDescription').val('')
  21. let p = $('<p>');
  22. p.text(inputp);
  23.  
  24. let inputPrice = $('#toyPrice').val();
  25. $('#toyPrice').val('')
  26. if(inputPrice.match(/^\d+\.?\d+$/g)==null){isMatch=false;}
  27. if(inputp==''){isMatch=false;}
  28. let button = $('<button>').on('click',function(){
  29. div.remove();
  30. });
  31. button.text(inputPrice);
  32. if(isMatch==false){return;}
  33. div.append(h2);
  34. div.append(p);
  35. div.append(button);
  36.  
  37.  
  38. $('#christmasGiftShop').append(div);
  39. let title = $('#christmasGiftShop').find('h2').text()
  40.  
  41. })
  42. }
Advertisement
Add Comment
Please, Sign In to add comment