• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

Javascript Reffing Calculator

bulbasaur

Not quite e^(-(x-μ)²/(2σ²)) / (σ√(2π))
So, I'm making a calculator for ASB. My intents should be pretty clear by reading the code, but I'm a messy coder. Chrome's inspector says there's no errors, but it's not working.

HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Bulbasaur's Reffing Calculator</title>
</head>

<body>
<center><h2>Bulbasaur's Reffing Calculator</h2></center>

<form name="calculator">
<p>Evolution modifier:  <br>
<input type="radio" name="evo"> Stage 1 of 3<br>
<input type="radio" name="evo">Stage 2 of 3 or 1 of 2<br>
<input type="radio" name="evo">Stage 3 of 3 or 2 of 2 or 1 of 1<br>
Experience: <input type="text" name="exp" size="2"><br>
Same type? <input type="checkbox" name="stab"><br>
Your Sp/Atk changes: <input type="text" name="atk" size="2"><br>
Opponent's Sp/Def changes: <input type="text" name="def" size="2"><br>
Effectiveness:<br>
<input type="radio" name="effectiveness">Immunity<br>
<input type="radio" name="effectiveness">Double Resistance<br>
<Input type="radio" name="effectiveness">Resistance<br>
<input type="radio" name="effectiveness"checked>Neutral<br>
<input type="radio" name="effectiveness">Super Effective</br>
<input type="radio" name="effectiveness">Double Super Effective</br>
Base Power: <input type="text" name="bp" size="3"><br>
Other, multiplicative modifier: <input type="text" name="xmod" size="4"><br>
Other, additive modifier: <input type="text" name="+mod" size="2"><br>
PP: <input type="text" name="pp" size="2"><br>
<input type="button" value="Calculate" onclick="calculate()" >
</form>
<script language="javascript" type="text/javascript">
function calculate () {
if (document.calculator.evo[0].checked){
window.evo=0;
}
if (document.calculator.evo[1].checked){
window.evo=1;
}
if (document.calculator.evo[2].checked){
window.evo=2;
}
if (document.calculator.effectiveness[0].checked){
window.effectiveness=0;
}
if (document.calculator.effectiveness[1].checked){
window.effectiveness=0.5;
}
if (document.calculator.effectiveness[2].checked){
window.effectiveness=(2/3);
}
if (document.calculator.effectiveness[3].checked){
window.effectiveness=1;
}
if (document.calculator.effectiveness[4].checked){
window.effectiveness=1.5;
}
if (document.calculator.effectiveness[5].checked){
window.effectiveness=2;
}
if(document.calculator.stab.checked){
window.stab=1.25;
}
if(document.calculator.stab.checked==0){
window.stab=1;
}
if(document.calculator.xmod.value==null){
document.calculator.xmod.value=1;
}

expevomod = ((90 + Number(document.calculator.exp.value) + 5 * evo) / 100);

	damage = Math.floor(((stab * (Number(document.calculator.bp.value) + 10 * (Number(document.calculator.atk.value) - Number(document.calculator.def.value)) * effectiveness * expevomod * Number(document.calculator.xmod.value))) / 10) + Number(document.calculator.xmod.value));
	if(damage<1) {
	damage=1;
	}
	if (Number(document.calculator.bp.value)<70) {
	window.critdamage = Math.floor(((stab * ( 2 * Number(document.calculator.bp.value) + 10 * (Number(document.calculator.atk.value) - Number(document.calculator.def.value)) * effectiveness * expevomod * Number(document.calculator.xmod.value))) / 10) + Number(document.calculator.xmod.value));
	}
	if(Number(document.calculator.bp.value)>69) {
	window.critdamage = Math.floor(((stab * (Number(document.calculator.bp.value) + 10 * (Number(document.calculator.atk.value) - Number(document.calculator.def.value) + 70) * effectiveness * expevomod * Number(document.calculator.xmod.value))) / 10) + Number(document.calculator.xmod.value));
	}
	if(window.critdamage<1) {
	window.critdamage = 1;
	}
	energy = Math.floor((Math.pow(Math.log(Number(document.calculator.bp.value)),2))/(stab * Math.sqrt(Number(document.calculator.pp.value)) * expevomod));
	if(energy<1) {
	window.energy = 1;
	}
	if(window.effectiveness==0) {
	damage=0;
	critdamage=0;
	}
	document.getElementById('d').InnerHTML= damage + ', ' + critdamage + ' if it is a critical hit';
    document.getElementById('e').InnerHTML= energy;
	}
</script>

<p id="d">Damage:</p>
<p id="e">Energy:</p>
</body>
</html>
 
"InnerHTML" should start with a lowercase "i". It'll work if you fix that, I think.
 
This is totally irrelevant, but I thought I would mention it anyway: <center> is a deprecated tag. Consider using a div or p styled with text-align:center instead.
 
I'm using transitional. I like my <b>'s and my <u>'s and my <s>'s and especially my <marquee>'s ;_; But yeah. That's just me being lazy.
 
Kids, don't be like me! Learn from Butterfree's HTML guide, which teaches you clean, proper HTML, not from some book that's as old as you are! Guideline: if your book contains the <b> tag or mentions being compatible with Netscape in any way, shape, or form, don't use it! Remember, always practice valid HTML'ing!

Yeah, the book I read touched on HTML 3.0, which is older than I am. And when I got used to <sup> and <tt> and <small>, I just couldn't give them up, although I didn't have much trouble giving up <frame>. And since I can't really use 3.0 and expect pages to show up properly, I was sort of forced to use a 4.01 doctype :/ It took me ages to get used to actually closing my <p>'s.

inb4 flamewar about presentation and content and the separation thereof
 
Back
Top Bottom