fork download
  1. var customName = document.getElementById('customname');
  2. var randomize = document.querySelector('.randomize');
  3. var story = document.querySelector('.story');
  4.  
  5. function randomValueFromArray(array){
  6. var random = Math.floor(Math.random()*array.length);
  7. return array[random];
  8. }
  9.  
  10. 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.';
  11. var insertX = ['Willy the Goblin', 'Big Daddy', 'Father Christmas'];
  12. var insertY = ['the soup kitchen', 'Disneyland', 'the White House'];
  13. var insertZ = ['spontaneously combusted', 'melted into a puddle on the sidewalk', 'turned into a slug and crawled away'];
  14.  
  15. randomize.addEventListener('click', result);
  16.  
  17. function result() {
  18. var newStory = storyText;
  19. var xItem = randomValueFromArray(insertX);
  20. var yItem = randomValueFromArray(insertY);
  21. var zItem = randomValueFromArray(insertZ);
  22. newStory = newStory.replace(':insertx:',xItem);
  23. newStory = newStory.replace(':insertx:',xItem);
  24. newStory = newStory.replace(':inserty:',yItem);
  25. newStory = newStory.replace(':insertz:',zItem);
  26.  
  27. if(customName.value !== '') {
  28. var name = customName.value;
  29. newStory = newStory.replace('Bob',name);
  30. }
  31.  
  32. if(document.getElementById("uk").checked) {
  33. var weight = Math.round(300*0.0714286) + ' stone';
  34. var temperature = Math.round((94-32) * 5 / 9) + ' centigrade';
  35. newStory = newStory.replace('94 farenheit',temperature);
  36. newStory = newStory.replace('300 pounds',weight);
  37. }
  38.  
  39. story.textContent = story;
  40. story.style.visibility = 'visible';
  41. }
  42.  
Runtime error #stdin #stdout #stderr 0s 17128KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:1:0 ReferenceError: document is not defined