Advertisement
Threed90

Refactored

Jan 25th, 2022
796
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.   let textToManipulateElement = document.getElementById('text').value;
  4.   let namingConventionElement = document.getElementById('naming-convention').value;
  5.   let resultElement = document.getElementById('result');
  6.  
  7.  
  8.   let resultString = '';
  9.  
  10.   let textToManipulateElementArr = textToManipulateElement.split(' ');;
  11.  
  12.   if(namingConventionElement === 'Camel Case'){
  13.  
  14.  
  15.     for(let i = 0 ; i < textToManipulateElementArr.length ; i++){
  16.       if(i === 0){
  17.         resultString += textToManipulateElementArr[i].toLowerCase();
  18.  
  19.       }else{
  20.  
  21.         let word = textToManipulateElementArr[i];
  22.         let firstLetter = word[0].toUpperCase();
  23.  
  24.         word = word.toLowerCase();
  25.         resultString += (firstLetter + word.slice(1));
  26.  
  27.  
  28.  
  29.       }
  30.     }
  31.  
  32.     resultElement.textContent = resultString;
  33.  
  34.  
  35.   }else if(namingConventionElement === 'Pascal Case'){
  36.  
  37.     for(let i = 0 ; i < textToManipulateElementArr.length ; i++){
  38.  
  39.         let word = textToManipulateElementArr[i];
  40.         let firstLetter = word[0].toUpperCase();
  41.  
  42.         word = word.toLowerCase();
  43.         resultString += (firstLetter + word.slice(1));
  44.  
  45.  
  46.     }
  47.     resultElement.textContent = resultString;
  48.  
  49.  
  50.   }else{
  51.     resultElement.textContent = 'Error!'
  52.  
  53.   }
  54. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement