Back to Freecodecamp

Step 13

curriculum/challenges/english/blocks/workshop-teacher-chatbot/66b6fdb76441c738719039fa.md

latest1.9 KB
Original Source

--description--

In previous lessons, you learned how to access the last character in a string like this:

js
const firstName = "Jessica";

// returns "a"
firstName[firstName.length - 1];

string.length - 1 will always give you the last index number for a string.

Create a new variable called lastCharacter and assign it the value of the last character in the subject variable.

Then, log the value of the lastCharacter variable to the console.

--hints--

You should have a variable called lastCharacter.

js
assert.isNotNull(lastCharacter);

You should assign the value of the last character in the subject variable to the lastCharacter variable. Refer to the example if you need help.

js
assert.strictEqual(lastCharacter, subject[subject.length - 1]);

You should log the value of the lastCharacter variable to the console.

js
assert.match(code, /console\.log\(lastCharacter\)/);

--seed--

--seed-contents--

js
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}.`);

--fcc-editable-region--

--fcc-editable-region--