Silly story generator Assesment wanted

Assessment wanted for Silly story generator.

Hi, I just started going through the Learning web development series. I’d be happy if i could get an assessment on what i did on the Silly story generator at https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Silly_story_generator

Link to my solution is available for assessment and criticism (that helps me a lot) at https://codepen.io/Paul-Ben/pen/QWVgBmm

Thanks.

Paul-Ben

1 Like

Hi, Paul-Ben :wave:
Congratulations, you passed the test.

Okay Paul, this is from me: :smiley:

  1. you can use replaceAll() method for xItem, and you can place method directly after another method (it’s you prefer).
  newStory = newStory.replace(":insertx:", xItem);
  newStory = newStory.replace(":insertx:", xItem);
  newStory = newStory.replace(":inserty:", yItem);
  newStory = newStory.replace(":insertz:", zItem);

like this:

  newStory = newStory
    .replaceAll(':insertx:', xItem)
    .replace(':inserty:', yItem)
    .replace(':insertz:', zItem);
  1. Take advantage template literal
  if(document.getElementById("uk").checked) {
    const weight = Math.round(300);
    const temperature =  Math.round(94);
    const stoneWeight = Math.floor(Math.round(weight/14));
    const celciusTemp = Math.floor(Math.round((5/9)*(temperature-32)))
    newStory = newStory.replace('94', celciusTemp);
    newStory = newStory.replace('fahrenheit', 'centigrade');
    newStory = newStory.replace('300', stoneWeight);
    newStory = newStory.replace('pounds', 'stone');
  }

:rocket:

 if (document.getElementById('uk').checked) {
    const weight = `${Math.round(300 / 14)} stone`;
    const temperature = `${Math.round(((94 - 32) * 5) / 9)} centigrade`;
    newStory = newStory
      .replace('94 fahrenheit', temperature)
      .replace('300 pounds', weight);
  }

:vulcan_salute:

1 Like