Help writing script
I'm trying to write a script that will calculate the moon's phase based on the entered value for the position and then using basic math functions
here's what I know....
each member has a different position for the moon, they view the source code and find the number value for the position, they then enter it into the input box on my forum
if the number is >=180, it then subtracts 157.5 and divides by 22.5 then rounds the number up or down automatically
if the number is <180, it then adds 202.5 and divides by 22.5 then rounds the number up or down automatically
I've posted this on tons of other forums and only one person has tried to help
he gave me this code:
function calculate(position) {
var phase;
position = parseFloat(position);
if (position > 180) {
phase = Math.round((position - 157.5) / 22.5);
provideAnswer(phase);
}
else if (position < 180) {
phase = Math.round((position - 202.5) / 22.5);
provideAnswer(phase);
}
else {
var text = document.createTextNode("You must enter a number!");
document.getElementsByTagName("div")[0].appendChild(text);
}
}
function provideAnswer(phase) {
// Do Something
}
and then the html code was:
<div>
<input type="text" id="position">
<input type="submit" onclick="calculate('position');">
</div>
but when I tried that it only wrote You must enter a number! over and over again... then he wrote back that the code was wrong:
calculate('position') should be calculate(document.getElementById('position').valu e)
there are 2 instances of this: one in the javascript and one in the html coding, but no matter what that just completely disabled the whole thing....
I'm lost, help please?
|