divanov94

Untitled

Aug 5th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function warriorQuest(input){
  2.     let crypted=input.shift();
  3.     for(let line of input) {
  4.         if(line==="For Azeroth"){
  5.             break;
  6.         }
  7.         let [command,firstValue,secondValue,thirdValue]=line.split(" ");
  8.         if(command==="GladiatorStance"){
  9.             crypted=crypted.toUpperCase();
  10.             console.log(crypted)
  11.  
  12.         }else if(command==="DefensiveStance"){
  13.             crypted=crypted.toLowerCase();
  14.             console.log(crypted)
  15.  
  16.         }else if(command==="Dispel"){
  17.             let index=Number(firstValue);
  18.             let letterToReplace=secondValue;
  19.             if(index>=0 && index<crypted.length){
  20.                 let toReplace=crypted[index];
  21.                 crypted=crypted.replace(toReplace,letterToReplace);
  22.                 console.log(`Success!`);
  23.  
  24.             }else {
  25.                 console.log(`Dispel too weak.`);
  26.             }
  27.  
  28.         }else if(command==="Target"){
  29.             if(firstValue==="Change"){
  30.                 while (crypted.includes(secondValue)){
  31.                     crypted=crypted.replace(secondValue,thirdValue);
  32.                 }
  33.                 console.log(crypted)
  34.             }else if(firstValue==="Remove"){
  35.                 while(crypted.includes(secondValue)){
  36.                     crypted=crypted.replace(secondValue,"");
  37.                 }
  38.                 console.log(crypted)
  39.  
  40.             }else {
  41.                 console.log(`Command doesn't exist!`)
  42.            }
  43.        }else {
  44.            console.log(`Command doesn't exist!`);
  45.         }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.     }
  52. }
Add Comment
Please, Sign In to add comment