【发布时间】:2014-10-31 04:16:42
【问题描述】:
您好,我制作了一首 99 瓶啤酒歌曲,但我的代码似乎无法正常工作,我不确定,我无法弄清楚。我真的需要一些帮助来看看我哪里出错了,或者需要一些帮助来显示我哪里出错了。我想要 if 语句或者是否有不同的方法可以做到这一点,但我需要设置它是如何的,我不确定如何修复它,请帮忙。 提前致谢。
这是我的 JavaScript。
var bottles = 99
bottle = "bottles";
text = "";
var output = document.getElementById('output');
while (bottles > 0) {
if (bottles == 1) {
bottle = "bottle";
text = "<p>" + bottles + " " + bottle + " of beer on the wall, " + bottles + " " + bottle + " of beer. <br/>";
bottles--;
output.innerHTML += text;
}
if (bottles == 0) {
bottles = "no more";
text += "Take one down and pass it around, " + bottles + " bottles of beer on the wall. </p>"
output.innerHTML += text;
}
output.innerHTML += "<p> No more bottles of beer on the wall, no more bottles of beer. <br/> Go to the store and buy some more, 99 bottles of beer on the wall.</p>"
这是我的 HTML。
<title>My Title</title>
<script src="javascript.js"></script>
<div style="text-align: center;">
<h1>99 Bottles of Beer Song</h1>
<div id="output"></div>
【问题讨论】:
-
你能提供一个jsfiddle吗?
-
从哪里开始?.....没有启动您的应用程序的事件。变量声明中的语法错误...
标签: javascript if-statement while-loop