Hello. Good evening! I just finished the Silly story generator exercise. I would like you to provide me with a correction to my code. I couldn’t get it to work…maybe my problem is in the insertion of the js file in the HTML. If so, and someone can explain it to me, I would appreciate it (I have tried in various ways without success. Regards
const customName = document.getElementById('customname');
const randomize = document.querySelector('.randomize');
const story = document.querySelector('.story');
function randomValueFromArray(array){
const random = Math.floor(Math.random()*array.length);
return array[random];
}
let storyText = 'It was 94 fahrenheit outside, so :insertx: went for a climb. 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.';
let insertX = ['Gandalff', 'Big Daddy', 'Father Christmas'];
let insertY = ['the soup kitchen', 'Maryland', 'the White House'];
let insertZ = ['spontaneously combusted', 'melted into a puddle on the sidewalk', 'turned into a slug and crawled away'];
randomize.addEventListener('click', result);
function result() {
let newStory = storyText;
let xItem = randomValueFromArray(insertX);
let yItem = randomValueFromArray(insertY);
let zItem = randomValueFromArray(insertZ);
newStory = newStory.replace(':insertx:', xItem);
newStory = newStory.replace(':inserty:', yItem);
newStory = newStory.replace(':insertz:', zItem);
newStory = newStory.replace(':insertx:', xItem);
if(customName.value !== '') {
const name = customName.value;
newStory = newStory.replace('Bob', name);
}
if(document.getElementById("uk").checked) {
const weight = Math.round(200 * 0.071429) + 'stone';
const temperature = Math.round((94 - 32) / 1.8) + 'centigrade';
newStory = newStory.replace('300 pounds', weight);
newStory = newStory.replace('94 fahrenheit', temperature);
}
story.textContent = newStory;
story.style.visibility = 'visible';
}