SKGreyHound

DOM Introduction 06. Format the Text

Jan 27th, 2021
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. function solve() {
  2. let inputStr = document.getElementById('input').value;
  3. let output = document.getElementById('output');
  4.  
  5. let input = inputStr.split('.');
  6. if (input.indexOf('') !== -1) {
  7. input.splice(input.indexOf(''), 1);
  8. }
  9.  
  10. if (input.length >= 3) {
  11. for (let i = 0; i < input.length; i += 3) {
  12. let arr = [];
  13. // if (input.length > 3)
  14. for (let y = 0; y < 3; y++) {
  15. if (i >= 3) {
  16. arr.push(input[i + y]);
  17. } else {
  18. arr.push(input[y]);
  19. }
  20. }
  21. let paragraph = arr.join('.');
  22. output.innerHTML += `<p> ${paragraph} </p>`;
  23. // let parHTML = document.createElement('p'); // Този начин и innerHTML дават същия резултат 40/100
  24. // parHTML.textContent = arr.join('.');
  25. // output.appendChild(parHTML);
  26. }
  27. } else {
  28. for (let i = 0; i < input.length; i++) {
  29. let arr = [];
  30. arr.push(input[i]);
  31.  
  32. let paragraph = arr.join('.');
  33. output.innerHTML += `<p> ${paragraph} </p>`;
  34. // let parHTML = document.createElement('p');
  35. // parHTML.textContent = arr.join('.');
  36. // output.appendChild(parHTML);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment