我认为自己是Javascript语言的新手,并且我的代码有问题。我试图模拟一个简单的if else语句,它涉及如果您的repel用完,程序会要求您使用另一个语句。但是,当我尝试在Chrome上运行它时,屏幕上没有显示任何内容。拒绝ifElse语句
这里是我的代码:
<html>
<head>
</head>
<body>
<script type = "javascript/text">
var repelsInBag = 10;
if (repelsInBag > 1){
document.write("Would you like to use another repel?");
}else{
document.write("Repel effect has ran out");
}
</script>
</body>
</html>
提前感谢!
- 斯蒂芬
将type属性更改为“text/javascript”或完全忽略它。 –
另外,将脚本标签放置在'
'标签的底部,以便脚本在标记呈现后运行。 –