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;
story.style.visibility = ‘visible’;
}