【发布时间】:2022-07-21 19:58:19
【问题描述】:
我正在稳步学习 JavaScript,我正在尝试创建一个小页面,该页面包含一组单词并将它们放在一个句子中。我无法创建一个函数来让我的页面运行并正确显示在我的页。我已经想到我将以某种方式使用 math.floor(Math.random()) 但是我想出的任何东西都不起作用!有人对这个主题有什么想法吗?我已将我的 github 页面链接到这个问题,并将展示我的 html 和 Javascript。 https://github.com/calvinalee2006/MixedMessages
const lyricButton = document.getElementById('begin_lyric').addEventListener('click', event => {
if (event.target.className === 'text') {
}
});
let array = [
location = ["Miami", "New York", "California", "Texas", "Kansas"],
drinks = ["Tequila", "Soda", "Milk", "Tea"],
celebrity = ["Michael Jackson", "Obama", "Bennedict Cumberbatch", "elmo"],
action = ["nod", "point", "kindly gesture", 'pop my collar']
];
lyricButton.innerHTML = `We down in ${location} going hard tonight,
gonna throw down ${drinks} like its going out of style,
Walk in the club fly like ${celebrity}.
When the DJ sees me ${action} he clears the floor,
for famous dance action that I am known for. `;
!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>Good Fortune!!</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<h1>Create your first club hit!</h1>
<p>Instructions:</p>
<ol>
<li>Select the club beat you want.</li>
<li>The dance club generator will create the beginning of your song </li>
<li>You can add the rest of the lyrics and create your own cub hit!!</li>
</ol>
<!--Button that needs to be pressed to get the result-->
<button id="begin_lyric" class="begin_lyrics">Beginning of your song!</button>
<!--The result-->
<h3 id="text"></h3>
<script src="script.js"></script>
</body>
</html>
【问题讨论】:
-
请确保您的代码示例运行正常。目前你有一些导致错误的错误。
-
您在此处发布的代码没有任何作用。您有一个
if声明,但它是空的。相关代码放在这里,不在github上。 -
addEventListener()不返回任何内容。所以LyricButton被设置为undefined,而不是begin_lyric元素。
标签: javascript html css