Okay this is easy all you really need to know is place holders. I'll use a easy code. We're gonna be making the substring for "Jan" in "January" "Melbourne is" in "Melbourne is great" (note the space!)
and "burgers" in "Hamburgers". Substrings start counting at 0. So it would be like this.
Okay so we have the place holder's now were gonna move onto the actual code. You first start with console.log
step 1.
Step 2. Now add the word/words your making a substring with it would be "January" (Remember the quotations). So now the code looks like this
Step 3. Adding the substring. You need to put .substring tells the console what you are doing with said text. Now the code will look like this.
Step 4. Find the values of letter's. You want the first 3 letter's in January so the values would be 0-3. You would put that in brackets like this again telling the console the values of said word you want to see. (0,3) So now the code will look like this.
Step 5. Closing the code. This is really important without it it will give you a syntax error. You use ); showing that that line is done. So now the finished code is this.
Now it will show Jan instead of January.
Other examples for tutorial
End result (Picture of the console log)
This is my first real tutorial on something other then making a normal command code so all feed back is good. Tell me where I can improve if needed. Being honest I'm not sure how good I did.
and "burgers" in "Hamburgers". Substrings start counting at 0. So it would be like this.
- Code:
0 1 2 3 4
| | | | |
h e l l o
Okay so we have the place holder's now were gonna move onto the actual code. You first start with console.log
step 1.
- Code:
console.log
Step 2. Now add the word/words your making a substring with it would be "January" (Remember the quotations). So now the code looks like this
- Code:
console.log("January"
Step 3. Adding the substring. You need to put .substring tells the console what you are doing with said text. Now the code will look like this.
- Code:
console.log("January".substring
Step 4. Find the values of letter's. You want the first 3 letter's in January so the values would be 0-3. You would put that in brackets like this again telling the console the values of said word you want to see. (0,3) So now the code will look like this.
- Code:
console.log("January".substring(0,3)
Step 5. Closing the code. This is really important without it it will give you a syntax error. You use ); showing that that line is done. So now the finished code is this.
- Code:
console.log("January".substring(0,3));
Now it will show Jan instead of January.
Other examples for tutorial
- Code:
console.log("January".substring(0,3));
console.log("Melbourne is great".substring(0,12));
console.log("Hamburgers".substring(3,10));
End result (Picture of the console log)
This is my first real tutorial on something other then making a normal command code so all feed back is good. Tell me where I can improve if needed. Being honest I'm not sure how good I did.