-2
<html>
     <h1>MB calculator</h1>

    <script type="text/javascript">
        var level = "0";
        var brawlpoints = "0";
        var brawlenergy = "0";
        var pointsmake = "0";

        function setlv() {
            level = document.forms["form"]["lv"].value;
            alert("level = " + level);
            var maxen = 95 + (level * 5);
            var exptolv = 110 + (level * 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 calculatevalues() {
        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()">
    <br>

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

</form>

    <h1>LV calculator</h1>

</html>

Put where the problem is in bold, for some reason that button does nothing when pushed...

So yea, test it in html, someone i know who knows some of html/javascript seems to think the form is broken or something like that...

EDIT: got it to work, how to round down in javascript if anyone reads this? EDIT: up, not down

theHeretic
  • 47
  • 1
  • 2
  • 12
  • 4
    Yeah. You have no doctype and you have no `` and `` elements. – Blender Jan 30 '13 at 05:02
  • Do you get an error or anything? – Explosion Pills Jan 30 '13 at 05:02
  • 3
    Please give a proper title to your question. If people face similar problems as you are, they will not be able to come here and check for the resolutions suggested by people – Shree Jan 30 '13 at 05:04
  • Don't use `document.write` - http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice – mrtsherman Jan 30 '13 at 05:07
  • @KennyKi - it's surrounded by **'s at the end of his code. He thought it would be bold when posted, but is not. – mrtsherman Jan 30 '13 at 05:07
  • the head/body have never mattered before, and i'm pretty certain i've ran it without doctype but i'll try the doctype thing... no i didn't get an error or i would have said something about it... sorry shree, couldn't think of any better titles, about the bolding error: thanks Derek, i didn't know that code didn't let me bold... anyway, what am i supposed to use other than document.write and why is it better? – theHeretic Jan 30 '13 at 05:14
  • @user1743752 `.innerHTML` – Derek 朕會功夫 Jan 30 '13 at 05:15
  • Umm... why is it any better, it just looks like a way to edit text rather than remove everything and write what is inside of it... who said i didn't want to get rid of everything? – theHeretic Jan 30 '13 at 05:21
  • @user1743752 For `document.write` you will have to deal with opening and closing the document, and with `innerHTML` you don't. – Derek 朕會功夫 Jan 30 '13 at 06:05

2 Answers2

2

You need to declare the maxen variable in the global scope

var level = "0"; var brawlpoints = "0"; var brawlenergy = "0"; 
var pointsmake = "0";
//declare the maxen variable here
var maxen = "0";

function setlv()
{
//left of your code
fmodos
  • 4,387
  • 1
  • 14
  • 17
0

Are you expecting this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><h1>MB calculator</h1>

<script type="text/javascript">

var level = "0"; var brawlpoints = "0"; var brawlenergy = "0"; var pointsmake = "0";
var maxen;
function setlv()
{
level = document.forms["form"]["lv"].value;
alert("level = " + level);
maxen = 95+(level*5);
var exptolv = 110+(level*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 calculatevalues()
{
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()">
<br>
**<input type="button" value="calculate" onclick="calculatevalues()">**
</form>

<h1>LV calculator</h1>

</HTML>

maxen is declared as a local variable in the function setlv and you are trying to access it in another function. Make it global

999k
  • 4,947
  • 2
  • 25
  • 32
  • Only difference i see is the first line, will test that but not sure what that does... – theHeretic Jan 30 '13 at 05:10
  • @user1743752 - he removed `var` from the function `setlv` for the variable `maxen`. He then moved `maxen` into the global scope. You call `math3 = maxen*1.75` later on - which fails because maxen didn't exist in the global scope. – mrtsherman Jan 30 '13 at 05:13
  • @mrtsherman Sorry i thought "maxen is declared as a local variable in the function setlv and you are trying to access it in another function". Make it global". This was enough :-) – 999k Jan 30 '13 at 06:03