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 ";
let storyTextCn = “外边有34度,:insertx: 出去遛弯。当走到 :inserty: 时小伙伴们都惊呆了,他 :insertz: 了。李雷全程目睹但他并没有慌,因为 :insertx: 是一个270斤的胖子,天气又辣么热”;
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() {
var newStory = storyText;
var newStoryCn = storyTextCn;
var xItem = randomValueFromArray(insertX);
var yItem = randomValueFromArray(insertY);
var zItem = randomValueFromArray(insertZ);
newStory = newStory.replace(’:insertx:’, xItem);
newStory = newStory.replace(’:inserty:’, yItem);
newStory = newStory.replace(’:insertz:’, zItem);
if (newStory.indexOf(’:insertx:’) !== -1) {
newStory = newStory.replace(’:insertx:’, xItem);
}else{
}
newStoryCn = newStoryCn.replace(’:insertx:’, xItem);
newStoryCn = newStoryCn.replace(’:inserty:’, yItem);
newStoryCn = newStoryCn.replace(’:insertz:’, zItem);
if (newStoryCn.indexOf(’:insertx:’) !== -1) {
newStoryCn = newStoryCn.replace(’:insertx:’, xItem);
}else{
}
if(customName.value !== ‘’) {
var name = customName.value;
newStory = newStory.replace(‘Bob’, name);
newStoryCn = newStoryCn.replace(‘李雷’, name);
}
if(document.getElementById(“uk”).checked) {
var weight = Math.round(300 * 0.071429);
var temperature = Math.round(94 / 17.2222);
newStory = newStory.replace(‘94 fahrenheit’, weight+’ stone’);
newStory = newStory.replace(‘300 pounds’, temperature+’ centigrade’);
story.textContent = newStory
} if (document.getElementById(“cn”).checked){
story.textContent = newStoryCn
}
else{
story.textContent = newStory ;
}
}
if my code has any bugs, let me know