console.log("Hi there!");
const botName = "teacherBot";
const greeting = `My name is ${botName}.`;
console.log(greeting);
const subject = "JavaScript";
const topic = "strings";
const sentence = `Today, you will learn about ${topic} in ${subject}.`;
console.log(sentence);
const strLengthIntro = `Here is an example of using the length property on the word ${subject}.`;
console.log(strLengthIntro);
console.log(subject.length);
console.log(`Here is an example of using the length property on the word ${topic}.`);
console.log(topic.length);
console.log(`Here is an example of accessing the first letter in the word ${subject}.`);
console.log(subject[0]);
console.log(`Here is an example of accessing the second letter in the word ${subject}.`);
console.log(subject[1]);
console.log(`Here is an example of accessing the last letter in the word ${subject}.`);
// User Editable Region
let lastCharacter = "subject.string.length[-1]";
console.log(lastCharacter);
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Just as subject[0] will access the first character of the subject string, you can find the index of the last character of a string by using the length property to find the end of the string.
For instance, if a string is 8 characters long then its final character will be at index 7 (zero-based indexing).
So the index number of the last character in any string can be expressed as the length of the string minus 1.
You can then put this expression inside the square brackets (i.e. subject[expression]), to find the final character of the string.
Why are you using quotation marks here? As @ILM says, you’re just creating a string literal.
Also, to find the length of a string, you need to use the length property directly on the string or variable which references it (in this case subject).
Finally, when you access the index of a string, you do not preface the square brackets with a dot (period).
console.log(Here is an example of accessing the last letter in the word ${subject}.);
//this the correct code for Build a Teacher Chatbot - Step 13
let lastCharacter = “t”;
console.log(lastCharacter