Assessment wanted for my Strings 1, 2, 3 & 4 skill test

Hi there! I would like to have an Assessment review after completing Useful string methods on MDN. Below are my code for review:

Strings: Task 1
Strings: Task 2
Strings: Task 3 (I have an issue with this)
Strings: Task 4

As for Strings: Task 3, I wonder why my code doesn’t work for converting the firstLetter to Capital letter.

It works when I called it, but doesn’t work with other sentences :grinning:

Thank you

Hi @tuhamworld

Well done! Here are some comments:

  • Task 1: :white_check_mark: Correct.
  • Task 2: :warning: Small misunderstanding. The idea is to calculate the second value of slice() to cut out the appropriate part of the quote. (Not to add the substring to it.) You’ll need the length of the substring for this.
  • Task 3: :warning: Mostly Correct. You need to change quote.slice(0,1) to lowerCase.slice(0,1). Otherwise you are replacing “I” (which doesn’t exist) instead of “i” .
  • Task 4: :white_check_mark: Correct.

On a general note: I don’t know why you have delete the line const section = document.querySelector('section'); from the given codes, but this prevents the result from being displayed in the output pane.

Happy coding,
Michael

1 Like

Thank you for the review.

I have make the necessary changes.

I often practise my code on the MDN Output page, and would then cut off the Javascript code.

It was a mistake leaving out the const section = document.querySelector('section'); part

1 Like

Task 3 is okay now. Task 2 looks still the same for me.

Understood :slightly_smiling_face:

1 Like

The more I tried to understand Task 2, the difficult it seems to be. I have made changes to my code.

May I ask if quoteLength is meant to calculate original quote or the new truncated quote?

quoteLength refers to the original quote.

For the second value of slice() you need to add index, substring.length and 1. This will cut from the beginning to the start of the index plus the length of the substring plus one for the dot at the end.

The result of the value of slice when adding index, substring.length and 1 seems to only give a 5 letters word which is green instead of the right answer :neutral_face:

.

What I meant is

const revisedQuote = quote.slice(0, index + substring.length + 1);

This should give you the required part of the quote.

Sorry, if I wasn’t clear enough :expressionless:

1 Like

Thank you for the clarification :grinning:

Now I completely understood the logic behind it. I have changed the code, and it is displaying correctly.

Can you please review my code on Strings: Task 2 again?

1 Like

Nice! That’s correct.

I’m glad I could help.

1 Like

Thank you for the patience, and correction.

1 Like

Hi,

For 3rd task, is the code below-mentioned code is correct?

const quote = ‘I dO nOT lIke gREen eGgS anD HAM’;

const lower = quote.toLowerCase();
const extractFirstLetter = lower.charAt(0);
const upper = extractFirstLetter.toUpperCase();
const fixed1 = lower.replace(extractFirstLetter, upper);
const fixedQuote = fixed1.replace(“green eggs and ham”, “chicken and kebab”);

console.log(fixedQuote);

Hi @Sarvotham_Gowda and welcome to the community :wave:

Yes, that looks right. :+1:

For future exercises it would be great to put your complete code into CodePen (or similar) like the other learner has done and create a new topic.

Have a nice day,
Michael