Get Help with Java Script Code: Calculate Day Count Since 1922 Dec. 18

  • Context: Java 
  • Thread starter Thread starter Helios
  • Start date Start date
  • Tags Tags
    Code Java
Click For Summary

Discussion Overview

The discussion centers around a JavaScript code snippet intended to calculate the number of days since December 18, 1922, and to derive the Brown Lunation Number (BLN) from that count. Participants seek to modify the code to achieve the desired output and troubleshoot issues related to its execution.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant provides an initial JavaScript code to calculate the day count since a specific date and suggests a formula for calculating the BLN using that count.
  • Another participant proposes a function to compute the BLN based on the day count, noting the difference between Java and JavaScript.
  • A participant shares a link to their webpage where the code is implemented but reports that it does not display the expected output.
  • Suggestions are made to replace the output method in the code to correctly display the BLN.
  • One participant encounters an output of "NaN" for the BLN and seeks further assistance.
  • Another participant suggests removing a part of the code that appends "Days" to the difference to resolve the issue.
  • There are indications that the code may be working after adjustments, with one participant expressing gratitude for the help received.
  • Further advice is given to replace the use of document.write with a method that creates a new HTML element for output, citing potential problems with document.write.

Areas of Agreement / Disagreement

Participants express differing views on the effectiveness of the code and the best methods for outputting results. The discussion includes both successful adjustments and ongoing issues, indicating that consensus on a final solution has not been reached.

Contextual Notes

There are unresolved issues regarding the handling of the day count and the calculation of the BLN, particularly concerning the output of "NaN." The discussion also highlights the distinction between Java and JavaScript, which may affect participants' understanding of the code.

Helios
Messages
267
Reaction score
63
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.
 
Technology news on Phys.org
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:
Dear David,
This is the page I put the code on.

http://www.helios.netne.net/brown.htm

Unfortunately, it doesn't show the output.
 
Replace
document.write("The Day Count is "+difference+" at present.")
with
document.write(bln(difference))
 
Dear David,
The output is now
Today's Brown Lunation Number is NaN & NaN / 51649

http://www.helios.netne.net/brown.htm
 
try taking out difference+=" Days"
 
Oh! I think it works. Thanks so much.
 
Helios said:
Oh! I think it works. Thanks so much.

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.