Advertisement
Mvelchev

Untitled

Aug 15th, 2022
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function emailValidator(input) {
  2.     let usersEmail = input.shift();
  3.  
  4.     while (input[0] !== 'Complete') {
  5.         let tokens = input.shift().split(' ');
  6.         let order = tokens[0];
  7.         switch (order) {
  8.             case 'Make':
  9.                 let toDo = tokens[1];
  10.                 if (toDo === 'Upper') {
  11.                     usersEmail = usersEmail.toUpperCase()
  12.                     console.log(usersEmail);
  13.                 } else if (toDo === 'Lower') {
  14.                     usersEmail = usersEmail.toLowerCase()
  15.                     console.log(usersEmail);
  16.                 }
  17.                 break;
  18.             case 'GetDomain':
  19.                 let count = tokens[1];
  20.                 let domain = usersEmail.slice(-count)
  21.                 console.log(domain);
  22.                 break;
  23.             case 'GetUsername':
  24.                 let index = usersEmail.indexOf('@');
  25.                 let userName = usersEmail.substring(0, index);
  26.                 console.log(userName);
  27.                 if (!usersEmail.includes('@')){
  28.                     console.log(`The email ${usersEmail} doesn't contain the @ symbol.`)
  29.                }
  30.                 break;
  31.            case 'Replace':
  32.                let char = tokens[1];
  33.                if (usersEmail.includes(char)){
  34.                    usersEmail = usersEmail.replaceAll(char,'-')
  35.                    console.log(usersEmail);
  36.                }    
  37.            case 'Encrypt':
  38.                for (let el of usersEmail){
  39.                    let chValue = String.fromCharCode(el);
  40.                    console.log(chValue);
  41.                }
  42.                
  43.            break;
  44.        }
  45.    }
  46. }
  47.  
  48.  
  49.  
  50. emailValidator((["Mike123@somemail.com",
  51.    "Make Upper",
  52.    "GetDomain 3",
  53.    "GetUsername",
  54.    "Encrypt",
  55.    "Complete"])
  56. )
  57. console.log('----------------------------------------');
  58. emailValidator((["AnotherMail.com",
  59.    "Make Lower",
  60.    "GetUsername",
  61.    "Replace a",
  62.    "Complete"])
  63. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement