Advertisement
TZinovieva

Activation Keys JS Fundamentals

Mar 27th, 2023
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function activationKeys(arr) {
  2.     let string = arr.shift();
  3.  
  4.     for (let line of arr) {
  5.         let instructions = line.split(">>>");
  6.  
  7.         if (instructions[0] === "Contains") {
  8.             if (string.includes(instructions[1])) {
  9.                 console.log(`${string} contains ${instructions[1]}`);
  10.             } else {
  11.                 console.log("Substring not found!");
  12.             }
  13.         } else if (instructions[0] === "Flip") {
  14.             let startIndex = Number(instructions[2]);
  15.             let endIndex = Number(instructions[3]);
  16.             let substring = string.substring(startIndex, endIndex);
  17.  
  18.             if (instructions[1] === "Upper") {
  19.                 substring = substring.toUpperCase();
  20.             } else {
  21.                 substring = substring.toLowerCase();
  22.             }
  23.  
  24.             string = string.slice(0, startIndex) + substring + string.slice(endIndex);
  25.             console.log(string);
  26.         } else if (instructions[0] === "Slice") {
  27.             let startIndex = Number(instructions[1]);
  28.             let endIndex = Number(instructions[2]);
  29.  
  30.             string = string.slice(0, startIndex) + string.slice(endIndex);
  31.             console.log(string);
  32.         } else if (instructions[0] === "Generate") {
  33.             console.log(`Your activation key is: ${string}`);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement