Hello,
I’m almost done with the assessment, but I don’t understand why I can only generate new story only once, unless I refresh the page. I would like if you would assist me in this. The link to my code is; https://glitch.com/edit/#!/plucky-efficacious-dolphin
At the bottom of your JavaScript file, you have some code sitting outside of a function. That means the code only runs once, when the page loads (or when you refresh the page).
All you need to do is add that code into your function result()
, so that it runs every time someone clicks on the “Generate random story”.
So, the beginning of your result function should look something like this:
function result() {
// Reset story with original storyText so that :insert: is present and can be used again
let newStory = storyText;
// Choose random value each time button is pressed
let xItem = randomValueFromArray(insertX);
I added some comments above each line to clarify the reasoning a bit. And just be sure you’re also moving any piece of code that needs to run each time the button is clicked, such as newStory = newStory.replace()
, etc.
Hope this helps!
Thanks a lot
Reading your comment gave me an haha moment and am even blaming myself for not spotting it. I do appreciate it a lot.
KEEP UP THE GOOD WORK