• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

JavaScript - Simple Get Easter Date

pexocafa

Competitor SERP Analyst
P Rep
0
0
0
Rep
0
P Vouches
0
0
0
Vouches
0
Posts
35
Likes
169
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 1000 XP
In this tutorial we will create a Simple Get Easter Date using JavaScript. This code will automatically calculate the given year to find the date of the easter day. The code use onclick() function to initiate a method that compute the given year to find the actual date for the easter day by passing the year in argument of getEaster() You can apply this script to your code to make your transaction faster, it is a user-friendly program feel free to modify it.

We will use JavaScript to add some new feature to the website interface by actually written into an HTML page. It is what gives your page a different interactive elements and animation that engage a user.

Getting Started:

This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. </

    head

    >
  7. <body

    >
  8. <nav class

    =

    "navbar navbar-defalt"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    JavaScript - Simple Get Easter Date</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  18. <div

    class

    =

    "col-md-6"

    >
  19. <form

    >
  20. <div

    class

    =

    "form-group"

    >
  21. <label

    >

    Enter a year</

    label

    >
  22. <input

    type

    =

    "number"

    id

    =

    "year"

    class

    =

    "form-control"

    /

    >
  23. </

    div

    >
  24. <center

    ><button

    type

    =

    "button"

    onclick

    =

    "displayDate();"

    class

    =

    "btn btn-primary"

    >

    Get Easter</

    button

    ></

    center

    >
  25. </

    form

    >
  26. <div

    id

    =

    "result"

    ></

    div

    >
  27. </

    div

    >
  28. </

    div

    >
  29. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  30. </

    body

    >
  31. </

    html

    >

Creating the Script

This code contains the script of the application. This code will display the easter date when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory
  1. var

    m=

    [

    "January"

    ,

    "February"

    ,

    "March"

    ,

    "April"

    ,

    "May"

    ,

    "June"

    ,

    "July"

    ,

    "August"

    ,

    "September"

    ,

    "October"

    ,

    "November"

    ,

    "December"

    ]

    ;


  2. function

    displayDate(

    )

    {
  3. var

    year=

    document.getElementById

    (

    'year'

    )

    .value

    ;

  4. if

    (

    year.length

    ==

    0

    )

    {
  5. alert(

    "Please enter something"

    )

    ;
  6. }

    else

    {
  7. var

    month=

    getEaster(

    year)

    [

    0

    ]

    ;
  8. var

    day=

    getEaster(

    year)

    [

    1

    ]

    ;
  9. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    "<h4>The date is: </h4><center><h2>"

    +

    m[

    month-

    1

    ]

    +

    " "

    +

    day+

    ", "

    +

    year+

    "</h2></center>"

    ;
  10. }
  11. }

  12. function

    getEaster(

    year)

    {
  13. var

    f =

    Math

    .floor

    ;
  14. var

    G =

    year %

    19

    ;
  15. var

    C =

    f(

    year /

    100

    )

    ;
  16. var

    H =

    (

    C -

    f(

    C /

    4

    )

    -

    f(

    (

    8

    *

    C +

    13

    )

    /

    25

    )

    +

    19

    *

    G +

    15

    )

    %

    30

    ;
  17. var

    I =

    H -

    f(

    H/

    28

    )

    *

    (

    1

    -

    f(

    29

    /

    (

    H +

    1

    )

    )

    *

    f(

    (

    21

    -

    G)

    /

    11

    )

    )

    ;
  18. var

    J =

    (

    year +

    f(

    year /

    4

    )

    +

    I +

    2

    -

    C +

    f(

    C /

    4

    )

    )

    %

    7

    ;
  19. var

    L =

    I -

    J;
  20. var

    month =

    3

    +

    f(

    (

    L +

    40

    )

    /

    44

    )

    ;
  21. var

    day =

    L +

    28

    -

    31

    *

    f(

    month /

    4

    )

    ;

  22. return

    [

    month,

    day]

    ;
  23. }

There you have it we successfully created a Simple Get Easter Date using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,501

352,162

352,176

Top