我正在试图制作一个基本的程序在html页面上运行。它给你一个答案点击一个按钮,并输入查询的东西后,看起来像:javascript-重置变量
<button type="button" onclick="whatsong()">Click to enter a song</button>
<p id="result"></p>
<script>
function whatsong() {
var song = prompt("please enter a song");
if (song = "example") {
document.getElementById("result").innerHTML = "yes";
}
if (song = "example2") {
document.getElementById("result").innerHTML = "no";
}
</script>
我希望变量song
复位,使用户可以输入打印no
到网页中的歌曲,然后再次按下按钮并输入一首能产生yes
的歌曲,但仍不会显示no
',就像现在一样,而是打印yes
。
UPDATE:http://istyjorapping.atwebpages.com/是实际的网页,它有多种选择,如果每(如 if (song == "heavydirtysoul", "ode to sleep", "fake you out", "forest") { document.getElementById("result").innerHTML = "yes"; }
),我已经试过到目前为止取得了给它一些奇怪的结果,调试器我通常使用不能工作的任何建议出。
正如您现在所看到的,您的代码已被整理,这是错误的,错过了关闭'} –
http://jshint.com/是你的朋友 – Quentin