forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-modification.js
More file actions
22 lines (17 loc) · 1.22 KB
/
Copy pathstring-modification.js
File metadata and controls
22 lines (17 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const input = require('readline-sync');
let str = "LaunchCode";
//1) Use string methods to remove the first three characters from the string and add them to the end.
//Hint - define another variable to hold the new string or reassign the new string to str.
firstStr = str.slice(0, 3);
lastStr = str.slice(3);
modifiedStr = lastStr.concat(firstStr);
//Use a template literal to print the original and modified string in a descriptive phrase.
console.log(`We removed the first three letters "${firstStr}" from ${str} and added them to "${lastStr}" with the result of ${modifiedStr}.`);
//2) Modify your code to accept user input. Query the user to enter the number of letters that will be relocated.
let userInput = input.question("Input the number of letters to be relocated: ");
let numLetterRelocate = Number(userInput);
//3) Add validation to your code to deal with user inputs that are longer than the word. In such cases, default to moving 3 characters. Also, the template literal should note the error.
if (numLetterRelocate > 10 || numLetterRelocate < 0) {
console.log(`Invalid Input. The maximum characters that can be selected is 10. Your selection was ${numLetterRelocate}. The default was set to 3.`);
numLetterRelocate = 3;
}