Silly Story Generator Variable Not Read

Hello please I need help with the Silly Story Generator. Although I was able to complete it after coming here to find solution and stumbled on the MDN source code for the assessment. Initially when I wrote the codes by myself, I can say I was absolute correct according to the source code. But in my second if function where the weight and temperature were declared I got a notification that the two variables were declared but not read. Please is there any explanation you can give to that.

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

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

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

//function randomValueFromArray() returns one of the item stored inside the array at random

function randomValueFromArray(array){

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

return array[random];

}

//texts strings that will act as input in the program

let 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.’;

let insertX = [‘Willy the Goblin’,‘Big Daddy’,‘Father Christmas’];

let insertY = [‘the soup kitchen’,‘Disneyland’,‘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 = It was 94 fahrenheit outside, so ${xItem} went for a walk. When they got to ${yItem}, they stared in horror for a few moments, then ${zItem}. Bob saw the whole thing, but was not surprised — ${xItem} weighs 300 pounds, and it was a hot day.;

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

let name = customName.value;

newStory = newStory.replace(‘Bob’,name);

}

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);

}

story.textContent = newStory;

story.style.visibility = ‘visible’;

}

Hi @segunthecanvas! I would be happy to look at this problem for you, but can you please put your example code into some kind of online code editor, like codepen or JS Fiddle? It is hard for me to see what is going on wth your code from the listing here, as Discourse has messed up the formatting a bit.

Thanks!

Hi @chrisdavidmills thanks for your quick response. This is my code it works fine now but before then I had the “variable declared but not read” error for the weight and temperature variables. I just want to know what might have caused it.