Assessment wanted for Silly story generator - Generating doesn't make sense

Hey, I’m currently having a little bit of trouble getting this to work. I’ve defined all my variables and managed to get the story to generate but the if statements aren’t making sense.

With what I have currently the name .replace works when the values are in US terms, but when it’s converted to UK values the name doesn’t work.

I also have a feeling that the way I have .replace defined in every if statement isn’t efficient, but without having them it just defaults back to the insert values in the string (:insertx: , :inserty: , :insertz:)

This is my CodePen : CodePen

If someone could have a look and tell me where im going wrong that would be great, thank you in advance!

Hello @timonthego

well done you doing great

just a little thing

change this line 

.replace("300", `${weight} stone`)
    .replace("94", `${temperature} celcius`)

to 

 .replace("300 pounds", `${weight} stone`)
    .replace("94 fahrenheit", `${temperature} celcius`).replace(/:insertx:/g, xItem) 

cause you need to replace the value and unit not just the value

hope that help and have a nice day :slight_smile:

Hey I have done this, but there is still the main issue with the name code not working when UK is selected. Any help there? haha

Hello @timonthego

i just checked you code again and it’s looks the same as the old version

maybe you need to click on save or something after you change it so i can get the updated version

hope that help and have a nice day :slightly_smiling_face:

Alright I have updated with the changes you sent before. I did forget to click save, my bad! :sweat_smile:

i was diving in the code already :joy:
glad that you figured it out

sometime it happen to me also :wink:

well done and have a nice day :slight_smile:

Hey, I managed to get this to work with help of a friend. What was going wrong is I was telling the program to replace storyText (our original string) and it made the code where it was changing above null (not registering)
replacing
newStory = storyText.replace("Bob", name);
with
newStory = newStory.replace("Bob",name);

in our if statements, fixed my issues as it now replaces within our new set variable (newStory). I hope this helps anyone who is looking for help

1 Like

well done :slight_smile:

1 Like