Advertisement
Silviya7

AdoptMe

Apr 26th, 2024
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     //TODO..
  3.  
  4.     const btnAdopt= document.getElementById('adopt-btn');
  5.     const InputType=document.getElementById('type');
  6.     const InputGender=document.getElementById('gender');
  7.     const InputAge=document.getElementById('age');
  8.  
  9.     btnAdopt.addEventListener('click',(e)=>{
  10.  
  11.     e.preventDefault();
  12.     if(!InputType.value || !InputGender.value || !InputAge.value){
  13.       return;
  14.     }
  15.   //console.log('success');
  16.  
  17.      
  18.    const ElementListAdotion=document.getElementById('adoption-info');
  19.    const Elementadoptedlist=document.getElementById('adopted-list');
  20.        
  21.    const Elementp1= document.createElement('p');
  22.    Elementp1.textContent=`Pet:${InputType.value}`;
  23.    const Elementp2= document.createElement('p');
  24.    Elementp2.textContent=`Gender:${InputGender.value}`;
  25.    const Elementp3= document.createElement('p');
  26.    Elementp3.textContent=`Age:${InputAge.value}`;
  27.  
  28.    const ArticleEl=document.createElement('article');
  29.    ArticleEl.appendChild(Elementp1);
  30.    ArticleEl.appendChild(Elementp2);
  31.    ArticleEl.appendChild(Elementp3);
  32.  
  33.    //btns
  34.    const EditBtn=document.createElement('button');
  35.    EditBtn.classList.add('edit-btn');
  36.    EditBtn.textContent='Edit';
  37.    const DoneBtn=document.createElement('button');
  38.    DoneBtn.classList.add('done-btn');
  39.    DoneBtn.textContent='Done';
  40.  
  41.    const ButtonContainer=document.createElement('div');
  42.    ButtonContainer.classList.add('buttons');
  43.    ButtonContainer.appendChild(EditBtn);
  44.    ButtonContainer.appendChild(DoneBtn);
  45.  
  46.    const LiElement= document.createElement('li');
  47.    LiElement.appendChild(ArticleEl);
  48.    LiElement.appendChild(ButtonContainer);
  49.    ElementListAdotion.appendChild(LiElement);
  50.  
  51.     InputType.value='';
  52.     InputGender.value='';
  53.     InputAge.value='';
  54.  
  55.     EditBtn.addEventListener('click',()=>{
  56.     let ListNodes=document.querySelectorAll('article p');
  57.     let AllList= Array.from(ListNodes);
  58.  
  59.     InputType.value=AllList[0].textContent.substring(4);
  60.     InputGender.value=AllList[1].textContent.substring(7);
  61.     InputAge.value=AllList[2].textContent.substring(4);
  62.  
  63.     LiElement.remove();
  64.      });
  65.  
  66.     DoneBtn.addEventListener('click',()=>{
  67.  
  68.     Elementadoptedlist.appendChild(LiElement);
  69.     //DoneBtn.remove();
  70.     //EditBtn.remove();
  71.  
  72.     ButtonContainer.remove();
  73.  
  74.     const BtnClear= document.createElement('button');
  75.     BtnClear.classList.add('clear-btn');
  76.     BtnClear.textContent='Clear';
  77.     LiElement.appendChild(BtnClear);
  78.  
  79.     BtnClear.addEventListener('click',()=>{
  80.     LiElement.remove();
  81.       });
  82.  
  83.      });
  84.     });
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement