Assessment wanted for my Silly story generator

Hello, I have completed the Assessment on Silly Story Generator and would really like my work to be Assessed.
  Here is my code on CodePen for the Assessment.

Troubles: My code is presently not working as it ought to but I assume the issue is from the Instruction on Completing the result() Step 3 on MDN.

(Screenshot here)

Looking forward to your help.

Hello there.
I checked your code and I found 2 problems in it:
First your constant variables insertX, insertY and insertZ should be array but yours is a template literal(string).
Second when you want to replace your x ,y ,z Items you’ve been suggested to use string methods(The 3 last lines in your code) not assignment.

  1. I have replaced my constant variables from template literal(string) to an Arrays.

  2. I am getting an error “Couldn’t access InsertX before initialization” after changing something in my constant variables storyText

  3. I didn’t get the last part of what you mean by using string methods instead of assignment? (The 3 last lines in my code)

  4. Can you please take another look at it, and tell what you think?

So I review your code and html file of MDN, and its seems like you have changed some code in storyText constant. In MDN html file it write :insertX: and you have changed it to ${insertX}. I guess your error in number 2 is for this.

You have used the string method replaceAll(). That’s good but you didn’t used it properly. I suggest to read the reference about replaceAll() method and try again.

By the way assignment in JavaScript is this ( = ) sign.


I had to redo the code again, so I can follow each step by step.
The content is being generated but the replacement is not still working

When you write code its good to have some plans and steps to do but you need to put them in right place. Your step 4 is totally useless cause it is OUTSIDE of the result function so when you call the function there are some missing parts.

The replace method returns a NEW string so when you use this method, you should save it in a variable unlike yours.
I mentioned this method a lot in past replies as well but it seems like you didn’t read the documentation of it. I put a link down below, i hope you study it.

By the way, there are 2 :insertX: in the text, you better use replaceAll method for that. Also I recommend to read about variable hoisting. I found an error for that in your code as well.

I post a link down below that is my code when I was studying like you I wrote it. You might wanna check it out:

1 Like

Finally discovered where the mistakes were.

Thank you :slight_smile:

Here’s the final code

1 Like