Skip to content

Commit b1e6b4d

Browse files
committed
string studio update
1 parent 1a451f6 commit b1e6b4d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

arrays/studio/string-modification.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
const input = require('readline-sync');
22
let str = "LaunchCode";
3-
3+
console.log(str);
44
//1) Use string methods to remove the first three characters from the string and add them to the end.
5-
//Hint - define another variable to hold the new string or reassign the new string to str.
65

7-
//Use a template literal to print the original and modified string in a descriptive phrase.
6+
//Hint - define another variable to hold the new string or reassign the new string to str.
7+
let strModified = str.replace("Lau", "") + str.slice(0,3);
8+
console.log(strModified);
89

910
//2) Modify your code to accept user input. Query the user to enter the number of letters that will be relocated.
11+
let userInput = input.question("Enter numer of letter to relocate: ");
12+
1013

1114
//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.
15+
let defult = 3;
16+
if(userInput > str.length) {
17+
console.log("Input number is longer than characters in word");
18+
} else {
19+
str.modified = str.slice(userInput, str.length ) + str.slice(0, userInput);
20+
console.log(strModified)
21+
}

0 commit comments

Comments
 (0)