Advertisement
ErolKZ

Untitled

Jan 24th, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. function solve() {
  2.  
  3. let text = document.getElementById('text').value;
  4.  
  5. let nameConv = document.getElementById('naming-convention').value;
  6.  
  7. if (nameConv === "Camel Case") {
  8.  
  9. text = text.split(' ');
  10.  
  11. text = text.map(el => el.toLowerCase());
  12.  
  13. text = text.map(el => el.split(''));
  14.  
  15. for (let i = 1; i < text.length; i++) {
  16.  
  17. text[i][0] = text[i][0].toUpperCase();
  18.  
  19. }
  20.  
  21. text = text.flat();
  22.  
  23. text = text.join('');
  24.  
  25. } else if (nameConv === "Pascal Case") {
  26.  
  27. text = text.split(' ');
  28.  
  29. text = text.map(el => el.toLowerCase());
  30.  
  31. text = text.map(el => el.split(''));
  32.  
  33. for (let i = 0; i < text.length; i++) {
  34.  
  35. text[i][0] = text[i][0].toUpperCase();
  36.  
  37. }
  38.  
  39. text = text.flat();
  40.  
  41. text = text.join('');
  42.  
  43. } else if (nameConv === "Another Case") {
  44.  
  45. text = 'Error!';
  46.  
  47. }
  48.  
  49. let result = document.getElementById('result');
  50.  
  51. result.textContent = text;
  52.  
  53. console.log(text);
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement