Silly story generator(https://developer.mozilla.org/zh-CN/docs/Learn/JavaScript/First_steps/Silly_story_generator)

/variable declared/
var customName = document.getElementById(‘customname’),
randomize = document.querySelector(’.randomize’),
story = document.querySelector(’.story’),
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 was not surprised — :insertx: weighs 300 pounds, and it was a hot day.’,
insertX = [‘Willy the Goblin’, ‘Big Daddy’, ‘Father Christmas’],
insertY = [‘the soup kitchen’, ‘Disneyland’, ‘the White House’],
insertZ = [‘spontaneously combusted’, ‘melted into a puddle on the sidewalk’, ‘turned into a slug and crawled away’];
console.log(storyText)
/return randomNumber/
function randomValueFromArray(array){
return array[Math.floor(Math.random()*array.length)];
}
/add click event to button/
randomize.addEventListener(‘click’, result);
function result() {
var newStory = storyText,//in order to each click newStory is initial
xItem = randomValueFromArray(insertX),
yItem = randomValueFromArray(insertY),
zItem = randomValueFromArray(insertZ);
newStory = newStory.replace(/:insertx:/g, xItem);
newStory = newStory.replace(/:inserty:/, yItem);
newStory = newStory.replace(/:insertz:/, zItem);
/myself method/
// var arr = newStory.split(’:’);
// arr[1] = xItem;
// arr[3] = yItem;
// arr[5] = zItem;
// arr[7] = xItem;
// storyText = arr.join(’:’);
// newStory = storyText.split(’:’).join(’’);

//Bob change to user enter custoname 

if(customName.value !== ‘’) {
var name = customName.value;
newStory = newStory.replace(‘Bob’,name);
}
//change show method
if(document.getElementById(“uk”).checked) {
var weight = Math.round(300 * 0.07142857142857142) + ’ stone’;
var temperature = Math.round((94 - 32) * 5 / 9) + ’ centigrade’;
newStory = newStory.replace(‘94 farenheit’,temperature);
newStory = newStory.replace(‘300 pounds’,weight);
/myself method/
// var weight = Math.round(300);
// var temperature = Math.round(94);
// newStory = newStory.replace(weight,21);
// newStory = newStory.replace(/farenheit/,‘centigrade’);
// newStory = newStory.replace(temperature,34);
// newStory = newStory.replace(/pounds/,‘stone’);
}
story.textContent = newStory;
story.style.visibility = ‘visible’;
}

Hi there @ms.zhangzb! I have checked your code, and the example works well —congratulations on some great work.

The only thing I did notice is that you wrote some of your comments like this:

/myself method/

Which broke the code. They should be like this:

//myself method

But apart from that, it was fine.

If you want to look at our finished example and check your work in more detail, see the links available at the main thread for this assessment — "Silly story generator" assessment

Actually, what is displayed in the post is a result of Discourse parsing the content as Markdown syntax because the code wasn’t code fenced. i.e. the comment in raw is
/*myself method*/
and the text inside the asterisks is displayed italicized in the cooked.

* I prefer three backticks on their own line before and after for block level to get highlighting (single backtick before and after for inline) over the Markdown indent syntax. eg.

```
<script>
function code(here) {
```

<script>
function code(here) { 

Ah, OK. Thanks for the explanation!

No worries in that case.