Assessment Silly Story Generator


I got my code working however when comparing it to yours, one thing was different. Is there any reason why you didn’t use a string literal versus the replace method?

Your code:
newStory = newStory.replace(’:insertx:’,xItem);
newStory = newStory.replace(’:insertx:’,xItem);
newStory = newStory.replace(’:inserty:’,yItem);
newStory = newStory.replace(’:insertz:’,zItem);

My code:
let storyText = It was 94 fahrenheit outside, so ${xItem} went for a walk. When they got to ${yItem} they stared in horror for a few moments, then ${zItem}. Bob saw the whole thing, but was not surprised — ${xItem} weighs 300 pounds, and it was a hot day.;

1 Like

Hello @kidatheart25

i think both will be fine as there many ways to solve any problem so maybe it was just to make student more familiar with calling function and maybe to search for another function than replace to replace all occurrence of insertx
look for replaceAll :wink:

hope that help and have a nice day

Thanks for the feedback!!

1 Like