我在下面的代码中做错了什么?

时间:2013-01-28 05:33:20

标签: javascript html

<html>

<h1>MB calculator</h1>

<script type="text/javascript">

var level = "0"; var brawlpoints = "0"; var brawlenergy = "0"; var pointsmake = "0";

function setlv()
{
level = docuent.forms["form"]["lv"].value;
alert("level = " + level);
}

var maxen = 95+(lv*5);
var exptolv = 110+(lv*15);

function setbpbe()
{
brawlpoints = document.forms["form"]["bp"].value;
brawlenergy = document.forms["form"]["be"].value;
alert("points per brawl = " + brawlpoints + "; energy per brawl = " brawlenergy);
}

function pointsupdate()
{
pointsmake = document.forms["form"]["p2m"].value;
alert("you want to make " + pointsmake);
}

function calculate()
{
var math1 = pointsmake/brawlpoints + 1;
var math2 = brawlenergy*math1;
var math3 = maxen*1.75;
var math4 = math2/math3 + 1;

document.write("To achieve your goal it will take you " + math1 + " brawls, this will take you " + math2 + " energy, or " + math4 + " levels, assuming a 75% refill levels you.);
}

</script>

<form name="form">

level:
<input type="text" name="lv" value="0">
<br>
<input type="button" value="update level" onclick="setlv()"> 
<br>
points per brawl done:
<input type="text" name="bp" value="0">
<br>
energy per brawl done:
<input type="text name="be" value="0">
<br>
<input type="button" value="update brawl energy and points" onclick="setbpbe()">
<br>
how many points you want to make:
<input type="text" name="p2m" value="0">
<br>
<input type="button" value="set points you want to make" onclick="pointsupdate()">
</form>

<input type="button" value="calculate" onclick="calculate()">

<h1>LV calculator</h1>

</html>

我看了几遍,我不知道我做错了什么...... 对不起发布整个事情,但我甚至无法真正缩小错误的位置,我检查了类似的代码,我的工作正常,我找不到其他的名称,我一致的差异。 ..按钮是不起作用的。谢谢你的帮助。

Javascript输出控制台

Uncaught ReferenceError: calculate is not defined test.html:64
Uncaught ReferenceError: pointsupdate is not defined test.html:61
Uncaught ReferenceError: setbpbe is not defined test.html:56
Uncaught ReferenceError: setlv is not defined test.html

点击每个按钮时的javascript输出控制台

2 个答案:

答案 0 :(得分:3)

你缺少很多东西:比如

// lv is not defined anywhere before using here
var maxen = 95+(lv*5);
var exptolv = 110+(lv*15);

在这里缺少concat运算符

alert("points per brawl = " + brawlpoints + "; energy per brawl = " brawlenergy);

应该是

alert("points per brawl = " + brawlpoints + "; energy per brawl = " + brawlenergy);

此处缺少收盘报价

document.write("To achieve your goal it will take you " + math1 + " brawls, this will take you " + math2 + " energy, or " + math4 + " levels, assuming a 75% refill levels you.);

应该是

document.write("To achieve your goal it will take you " + math1 + " brawls, this will take you " + math2 + " energy, or " + math4 + " levels, assuming a 75% refill levels you.");

还有更多 .. 养成使用javascript控制台的习惯,这样你才能知道代码出错的地方..

答案 1 :(得分:1)

您输入的文档存在一个拼写错误,而不是文档。可能是它导致错误。

相关问题