简单的笑话生成器(MDNcase)
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="btn">笑话生产</button>
<textarea name="" id="txt" cols="30" rows="10"></textarea>
</body>
<script>
//下列代码运行在node.js环境中
// const fs = require("fs");
// const path = './test.word'
// fs.readFile(path, function(error, data) {
// if (error) {
// console.log('读取文件失败了' + error)
// } else {
// console.log(data.toString());
// }
// })
//数组的一些操作练习
// let shopping = ['bread', 'milk', 'cheese', 'hummus', 'noodles'];
// let sequence = [1, 1, 2, 3, 5, 8, 13];
// let random = ['tree', 795, [0, 1, 2]];
// let myData = 'Manchester,London,Liverpool,Birmingham,Leeds,Carlisle';
// let myArr = myData.split(',');
// // console.log(myArr);
// let myNewString = myArr.join(',');
// // console.log(myNewString);
// let myNewString1 = myArr.toString();
// console.log(myNewString1);
//笑话生成器
const storyText = "今天气温50℃";
const insertX = "怪兽威利出门散步";
const insertY = "当他走到肯德基门口";
const insertZ = "突然就在人行道自燃了";
const btn = document.querySelector('#btn');
const txt = document.querySelector('#txt');
btn.addEventListener('click', function() {
let tempName = prompt('请输入一个自定义名字');
let newStory = storyText + "," + insertX + insertY + insertZ + "," + tempName + "全程目睹但丝毫不慌" + "," + "因为怪兽威利是一个 140 公斤的胖子,天气又辣么热。"
txt.innerHTML = newStory;
})
</script>
</html>
标签:const,log,生成器,MDNcase,let,console,btn,myArr,笑话 来源: https://blog.csdn.net/weixin_45330738/article/details/120900766