473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help with script

I need to make a script that will calculate the moon phase based on the moon's position... it's for an online game

here's what I've got - members locate the position by viewing the page source and it's always a number

then they would enter that number into an input box and submit it, which then would figure the answer one of 2 ways:

if the number is >=180, it subtracts 157.5 and then divides by 22.5, rounds the number and that's the answer

if the number is <180, it adds 202.5 and then divides by 22.5, rounds the number and that's the answer

I've posted on several different coding forums to try to get help: I wrote a script once before with lots of help from other people but I didn't know half of what I was doing or even what it all meant, just that it did what I wanted it to...

so on one forum someone posted this:

Expand|Select|Wrap|Line Numbers
  1. function calculate(position) {
  2.   var phase;
  3.   position = parseFloat(position);
  4.   if (position > 180) {
  5.      phase = Math.round((position - 157.5) / 22.5);
  6.      provideAnswer(phase);
  7.      }
  8.   else if (position < 180) {
  9.      phase = Math.round((position - 202.5) / 22.5);
  10.      provideAnswer(phase);
  11.      }
  12.   else {
  13.     var text = document.createTextNode("You must enter a number!");
  14.     document.getElementsByTagName("div")[0].appendChild(text);
  15.     }
  16.   }
  17.  
  18. function provideAnswer(phase) {
  19.   // Do Something
  20.   }
and the html code was
Expand|Select|Wrap|Line Numbers
  1. <div>
  2.   <input type="text" id="position">
  3.   <input type="submit" onclick="calculate('position');">
  4. </div>
all that did was write You must enter a number! over and over again

then he said that the code was wrong and that calculate('position') should be calculate(document.getElementById('position').valu e) but when I changed the values in both the script and the html it just disabled it completely

please help?
Feb 23 '07 #1
1 1152
acoder
16,027 Expert Mod 8TB
Try
Expand|Select|Wrap|Line Numbers
  1. var pos = parseFloat(position);
then replace position in the if statements with pos.

You should also check for invalid numbers using isNaN(pos).
Feb 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
4
by: Derek | last post by:
I have the following script in a page and it gets an error in IE 6. Says something about an invalid argument but the line number doesn't help since I can't see the javascript code when viewing...
7
by: mike | last post by:
Hello, I am kind of new to this javascript stuff and I am constantly having problems trying to get my webpage validated. I have the following <script>printdate();</script> and when I validate it...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.