Advertisement
Silviya7

Scary Story

May 21st, 2024
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function solve() {
  3.   //TODO ....
  4.  
  5.   const BtnPublish= document.getElementById('form-btn');
  6.   const PreviewList= document.getElementById('preview-list');
  7.   const DivMain= document.getElementById('main');
  8.  
  9.   //input fields
  10.   const InputName=document.getElementById('first-name');
  11.   const InputLName=document.getElementById('last-name');
  12.   const InputAge=document.getElementById('age');
  13.   const InputTitle=document.getElementById('story-title');
  14.   const InputGenre=document.getElementById('genre');
  15.  
  16.   const InputStory= document.getElementById('story');
  17.  
  18.   BtnPublish.addEventListener('click',(e)=>{
  19.  
  20.     e.preventDefault();
  21. if(InputName.value =='' || InputLName.value=='' || InputAge.value=='' || InputTitle.value=='' || InputGenre.value==''
  22. || InputStory.value=='' ){
  23.   return;
  24. }
  25.  
  26.  
  27.     const Elementh1= document.createElement('h4');
  28.     Elementh1.textContent=`Name:${InputName.value} ${InputLName.value}`;//6
  29.  
  30.     const Elp1= document.createElement('p');//5
  31.     Elp1.textContent=`Age: ${InputAge.value}`;
  32.  
  33.     const Elp2= document.createElement('p');
  34.     Elp2.textContent=`Title: ${InputTitle.value}`;//7
  35.  
  36.     const Elp3= document.createElement('p');
  37.     Elp3.textContent=`Genre: ${InputGenre.value}`;//7
  38.     const Elp4= document.createElement('p');
  39.     Elp4.textContent=`${InputStory.value}`;
  40.  
  41.     const Article = document.createElement('article');
  42.     Article.appendChild(Elementh1);
  43.     Article.appendChild(Elp1);
  44.     Article.appendChild(Elp2);
  45.     Article.appendChild(Elp3);
  46.     Article.appendChild(Elp4);
  47.  
  48.     const BtnSave= document.createElement('button');
  49.     BtnSave.classList.add('save-btn');
  50.     BtnSave.textContent='Save Story';
  51.  
  52.     const BtnEdit= document.createElement('button');
  53.     BtnEdit.classList.add('edit-btn');
  54.     BtnEdit.textContent='Edit Story';
  55.     const BtnDelete= document.createElement('button');
  56.     BtnDelete.classList.add('delete-btn');
  57.     BtnDelete.textContent='Delete Story';
  58.  
  59.    
  60.  
  61.     //
  62.     const LiElement= document.createElement('li');
  63.     LiElement.classList.add('story-info');
  64.     LiElement.appendChild(Article);
  65.     LiElement.appendChild(BtnSave);
  66.     LiElement.appendChild(BtnEdit);
  67.     LiElement.appendChild(BtnDelete);
  68.  
  69.     //
  70.    
  71.     PreviewList.appendChild(LiElement);
  72.  
  73.     BtnPublish.setAttribute('disabled','disabled');
  74.  
  75.      InputName.value='';
  76.      InputLName.value='';
  77.      InputAge.value='';
  78.      InputTitle.value='';
  79.      InputGenre.value='';
  80.  
  81.      InputStory.value='';
  82.  
  83.      BtnEdit.addEventListener('click',()=>{
  84.  
  85.       InputName.value=Elementh1.textContent.substring(5);
  86.  
  87.       let AllNames= Elementh1.textContent.split(' ');
  88.       InputLName.value=AllNames[1];;
  89.       InputAge.value=Elp1.textContent.substring(5);
  90.       InputTitle.value=Elp2.textContent.substring(7);
  91.       InputGenre.value=Elp3.textContent.substring(7);
  92.    
  93.       InputStory.value=Elp4.textContent;
  94.  
  95.       BtnSave.setAttribute('disabled','disabled');
  96.       BtnEdit.setAttribute('disabled','disabled');
  97.       BtnDelete.setAttribute('disabled','disabled');
  98.  
  99.       BtnPublish.removeAttribute('disabled');
  100.       LiElement.remove();
  101.      });
  102.  
  103.      BtnSave.addEventListener('click',()=>{
  104.       DivMain.innerHTML='';
  105.  
  106.       const Elementh=  document.createElement('h1');
  107.       Elementh.textContent='Your scary story is saved!';
  108.  
  109.       DivMain.appendChild(Elementh);
  110.  
  111.      });
  112.      BtnDelete.addEventListener('click',()=>{
  113.       LiElement.remove();
  114.       BtnPublish.removeAttribute('disabled');
  115.      })
  116.    
  117.   })
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement