Help/Assessment wanted for Silly story generator

Hello, I am new to coding and would greatly appreciate some help with the JS assessment. I’ve gotten the first instance of replacing insertX to work, and the custom name, but none of the other inserts or UK conversions are working. Where am I going wrong?

Hey there @rioDBMG, thanks for sending in your code, and welcome to the community!

So looking at this, you’ve got the code mostly right. JSBin was giving me some funny results when trying to tets it, so I ended up testing it locally instead.

The only thing I found to not be working was the UK->US temperature/weight conversion. I updated it to this, and it worked:

if(document.getElementById("uk").checked) {
    let weight = Math.round(300*0.0714286)+" stone";
    let temperature =  Math.round((94-32)*5/9)+" centigrade";
      newStory=newStory.replace("94 fahrenheit",temperature)
      newStory=newStory.replace("300 pounds",weight)

  }

The notable changes are:

  1. 2 instances of storyText.replace changed to newStory=newStory.replace — just like the other replace calls, you want to create a new version of newStory with the change made, and replace the old version with it. storyText.replace creates a version of the original story template with the change made, and then doesn’t assign it to anything.
  2. spaces put before stone and centigrade, so that there is a space between the value and the unit in each case.

Apart from that, your code worked fine — good work here, well done!

@chrisdavidmills Man thanks a million I really appreciate it! I poured over this for hours before deciding to ask for help. knowing that I wasn’t too far off gives me the confidence to keep pushing forward.

@rioDBMG cool! Yeah, you keep going, and you’ll get this just fine.

1 Like