Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java Script Code help needed

  1. Dec 14, 2009 #1
    Dear Computer People,
    I know nothing about Java. What I understand what "Java script" means is something that one can paste into an html document or web page. What I have is a Java script code that displays a day count since 1922 December 18. Here it is.

    <script>
    var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
    function countup(yr,m,d){
    var today=new Date()
    var todayy=today.getYear()
    if (todayy < 1000)
    todayy+=1900
    var todaym=today.getMonth()
    var todayd=today.getDate()
    var todaystring=montharray[todaym]+" "+todayd+", "+todayy
    var paststring=montharray[m-1]+" "+d+", "+yr
    var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1)
    difference+=" Days"
    document.write("The Day Count is "+difference+" at present.")
    }
    //enter the count up date using the format year/month/day
    countup(1922,12,18)
    </script>

    As you can see (1922, 12, 18) is in the last line of code.
    Now I would think that this day count D could be used in the function,

    BLN = D*( 1749 / 51649 ) - 781 / 51649

    where BLN is the "Brown Lunation Number",
    and the altered code could yield an output that would appear as ( for example )

    Today's Brown Lunation Number is 1075 & 48302 / 51649

    If anyone can offer this Java script code, I am grateful.
     
  2. jcsd
  3. Dec 14, 2009 #2

    DavidSnider

    User Avatar
    Gold Member

    Not sure if I got the math right, but:

    function bln(d) {
    var n = d * ( 1749 / 51649 ) - 781 / 51649;
    var frac = (n - parseInt(n,10));
    var denom = 51649;
    var numer = frac * denom;

    return "Today's Brown Lunation Number is " + parseInt(n,10) + " & " + parseInt(numer,10) + " / " + denom;
    }

    P.S. Java and javascript are completely different languages
     
    Last edited: Dec 14, 2009
  4. Dec 14, 2009 #3
  5. Dec 14, 2009 #4

    DavidSnider

    User Avatar
    Gold Member

    Replace
    document.write("The Day Count is "+difference+" at present.")
    with
    document.write(bln(difference))
     
  6. Dec 15, 2009 #5
  7. Dec 15, 2009 #6

    DavidSnider

    User Avatar
    Gold Member

    try taking out difference+=" Days"
     
  8. Dec 15, 2009 #7
    Oh!! I think it works. Thanks so much.
     
  9. Dec 15, 2009 #8

    DavidSnider

    User Avatar
    Gold Member

    Also, I would suggest that in your javascript replace document.write(bln(difference)) with:

    var elm = document.createElement("div");
    elm.innerHTML = bln(difference);
    document.body.appendChild(elm);

    Document.write causes problems.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook