【发布时间】:2019-05-13 06:55:19
【问题描述】:
我想检查 woodCount 变量是否等于或大于 25 我想在页面上显示一个新按钮。现在我只是让它 console.log 真或假。
对不起,如果这真的很容易或没有意义,但我是 Javascript 新手。谢谢!
JAVASCRIPT 文件
var woodCount = 0;
var gatherWood = document.getElementById("gatherWood");
var wood = document.getElementById("wood");
gatherWood.onclick = function(){
woodCount++;
wood.innerHTML = woodCount;
}
function fire() {
if woodCount >= 25 {
console.log('True');
}else{
console.log('False');
}
}
HTML 文件
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Game</title>
<meta name="description" content="Game">
<meta name="author" content="SitePoint">
<script src="game.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<input class="woodbtn" type="button" value="Gather Wood" id="gatherWood" />
Wood = <span id="wood">0</span>
</div>
</body>
</html>
【问题讨论】:
-
if woodCount >= 25 {是无效语法,if条件需要用括号括起来
标签: javascript html css