Hello!
I just finished my Silly story generator and I’d like someone to have a look at it. Thanks a lot!
var customName = document.getElementById(‘customname’);
var randomize = document.querySelector(’.randomize’);
var story = document.querySelector(’.story’);
function randomValueFromArray(array){
return array[Math.floor(Math.random()*array.length)];
}
var storyText = "It was 94 farenheit 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 he was not surprised — :insertx: weighs 300 pounds, and it was a hot day.”;
var insertX = ["Willy the Goblin ", "Big Daddy ", "Father Christmas "];
var insertY = ["the soup kitchen ", "Disneyland ", "the White House "];
var insertZ = ["spontaneously combusted ", "melted into a puddle on the sidewalk ", "turned into a slug and crawled away "];
randomize.addEventListener(‘click’, result);
function result() {
var newStory = storyText;
var itemX = randomValueFromArray(insertX);
var itemY = randomValueFromArray(insertY);
var itemZ = randomValueFromArray(insertZ);
if(customName.value !== ‘’) {
var name = customName.value;
}
if(document.getElementById(“uk”).checked) {
var weight = Math.round(300 / 7) + " kgs";
var temperature = Math.round(94 / 2.8) + " centigrade";
} else if(document.getElementById(“us”).checked) {
var weight = Math.round(300) + " stone";
var temperature = Math.round(94) + " fahrenheit";
}
story.textContent = "It was " + temperature + " farenheit outside, so " + itemX + " went for a walk. When they got to " + itemY + ", they stared in horror for a few moments, then " + itemZ + " " + name + " saw the whole thing, but he was not surprised — " + itemX + weight + “, and it was a hot day.”;
story.style.visibility = ‘visible’;
}