我正在看一个教程并遵循他的代码,但我自己命名了变量和函数,但是在我完成buyHelper
函数之后,我的loadCode
函数停止工作并且它一直说“{”是意外的。请帮忙。(除了css,我在一个文件中完成了所有代码,因为它不能在外部工作)
<!DOCTYPE html>
<script type="text/javascript">
function update(){
document.getElementById("amount").value = codeAmount;
document.title = codeAmount + " Codes"
}
var codeAmount = 0;
var codeHelper = 0;
function timer(){
codeAmount = codeAmount + codeHelper;
update()
}
setInterval(timer, 1000);
</script>
<html>
<head>
<title>0 Codes</title>
<link rel="stylesheet" type="text/css" href="clickerGame2.css">
</head>
<body>
<h1>Click to get JavaScript code!</h1>
<h2>Use your code to get upgrades!</h2>
<a href=# onclick="addJS()"><img
src="https://i.stack.imgur.com/Mmww2.png" alt="JS Logo" width="150"
height="150" class="pulse"></a>
<br><br>
You Have:
<input type="text" id="amount" disabled style>
<script type="text/javascript">
function addJS(){
codeAmount = codeAmount + 1;
update()
}
</script>
lines of code.
<br><br>
<button><a href=# onclick="saveCode()" class="white">Save!</a>
</button>
<button><a href=# onclick="loadCode()"class="white">Load!</a>
</button>
<br><br>
<p>Pay someone to help code!</p>
<button><a href=# onclick="buyHelper()">Helper</a></button>
<p id="helperCost"></p>
<p id="helperAmount">You have 0 helpers.</p>
<script type="text/javascript">
function saveCode(){
localStorage.setItem("codeAmount", codeAmount);
}
function loadCode(){
codeAmount = localStorage.getItem("codeAmount");
codeAmount = parseInt(codeAmount);
update();
}
function buyHelper(){
if (codeAmount >= ((codeHelper+1)*12){
codeAmount = codeAmount - ((codeHelper+!)*12);
codeHelper = codeHelper + 1;
update();
}
}
</script>
</body>
</html>