Asssessment wanted for silly quote generator

I have tried all effort but to no avail. my replace method is not working.

//here is the code

‘use strict;’

const customName = document.getElementById(‘customname’);

const randomize = document.querySelector(’.randomize’);

const story = document.querySelector(’.story’);

document.querySelector(‘html’).style.backgroundColor = ‘red’;

function randomValueFromArray(array){

const random = Math.floor(Math.random()*array.length);

return array[random];


const storyText = It was 94 fahrenheit outside, so :insertx: went for a walk. When they got to :inserty:, they stared in horror for a few moments, then :insertz:. Bob saw the whole thing, but was not surprised — :insertx: weighs 300 pounds, and it was a hot day.;

const insertX = [

'Willy the Goblin',

'Big Daddy',

'Father Christmas'


const insertY = [

'the soup kitchen',

'Disney land',

'The white house'


const insertZ = [

'spontaneously combusted',

'melted into a puddle on the side walk',

'turned into a slug and crawled away'


const xItem = randomValueFromArray(insertX);

const yItem = randomValueFromArray(insertY);

const zItem = randomValueFromArray(insertZ);

const newStory = storyText;

newStory.replace(’:insertx:’, xItem);

newStory.replace(’:inserty:’, yItem);

newStory.replace(’:insertz:’, zItem);

randomize.addEventListener(‘click’, result);

function result() {

if(customName.value !== ‘’) {

const name = customName.value;

newStory.replace('Bob', name);


if(document.getElementById(“uk”).checked) {

const poundsToStone = (300 / 14);

const fahrenheitToCentigrade = (94 - 32) * 5/9;

const weight = Math.round(poundsToStone);

const temperature =  Math.round(fahrenheitToCentigrade);

newStory.replace('94 fahrenheit', weight);

newStory.replace('300 pounds', temperature);


story.textContent = newStory; = ‘visible’;


Hi @jonathan_friday and welcome to the community :wave:

Could you please put your code into an online code editor like or The forum replaced some characters from your current post which makes it hard to debug.


i will do just that.


A few hints to get you further:

  • All newStory “stuff” should be inside the result() function, so it changes every time we press the button.
  • newStory can’t be const because we need to change it in this exercise.
  • The replace() method returns a new string with the changes so you need to assign this return value to newStory.

Please tell me if you need more help or want me to look at a new version of your code. When you save a Fiddle its URL changes so make sure to post the new link here.

Good luck, :slightly_smiling_face:

This is still missing. All replace() calls need to look like this:

newStory = newStory.replace('Bob', name);

See how I save the return value of the method into newStory again? This makes sure that newStory now contains the replacement.
Remember that replace() doesn’t change the string itself but returns a new string with the changes.

Good morning sir!
it’s working fine now. Thank you so much!

1 Like

I’m glad to hear that.
Come back whenever you have more questions and/or you want us to look at another exercise. :slightly_smiling_face: