Evaluation needed for Silly Story Generator

Hello sir, here is the link of my attempt
A Pen by Cleo (codepen.io)

Eagarly waiting for your assessment and remarks.
Thanks

Nice work again, @Cleo_Shepsut

There’s only one small mistake. You’re missing a space in the “weight replace” code. This causes it to not find “300 pound”.

As a small simplification you could use replaceAll() for :insertx: to replace both occurrences in one go.

See you,
Michael

Hello sir, thanks for the assessment, the space in between 300 and pound was adjusted but the replaceALL ??? Always say replace all is not a function. I don’t know how to fix, Any clue? Thanks.

Did you write “replaceALL”? Because this should be “replaceAll”. JavaScript is case-sensitive. This line works:

newStory = newStory.replaceAll(':insertx:', xItem);

Also be aware that this function doesn’t work on “Internet Explorer”.

Hello sir, the( newStory = newStory.replaceAll(’:insertx:’, xItem):wink: is still not working .

1 Like

Hmm… :thinking:
Could you please update your CodePen with the new code? So I can see the error myself.

Which browser are you using to test the code?

Hello sir, looks like upgrading CodePen requires some kind of payment .

I didn’t mean to upgrade your CodePen account.
Have you saved after making changes? If you have updated and saved your code on CodePen, I should see the newest version of your code. Maybe the link has changed? In this case just post the new link.

Just saved the changes you requested but the replaceAll() is not working, you can check it and see

1 Like

Ahhh, I see.

The replacing works for both occurrences of :insertx:. That’s fine, but you still need the other two replace() lines for :inserty: and :insertz:.

The whole “magic” of replaceAll() is that it will change all occurrences of a certain value (in this case :insertx:) in the text.

So, how should I apply your suggestion now?

This will work:

newStory = newStory.replaceAll(':insertx:', xItem);
newStory = newStory.replace(':inserty:', yItem);
newStory = newStory.replace(':insertz:', zItem);

Another possibility would be to use replace() twice in a row for :insertx:

newStory = newStory.replace(':insertx:', xItem);
newStory = newStory.replace(':insertx:', xItem);
newStory = newStory.replace(':inserty:', yItem);
newStory = newStory.replace(':insertz:', zItem);

Each of the two calls will change one of the :insertx:.

Does that make it clearer?

Yeah , the replaceAll() is working now as you suggested .

1 Like

Cool! :slightly_smiling_face:

I’m glad we could figure it out.