• We just launched and are currently in beta. Join us as we build and grow the community.

How to Get the Actual Easter Date in JavaScript

sdqwdwe

Waifu Protector
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
152
Likes
103
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
How to Get the Actual Easter Date in JavaScript

Introduction

In this tutorial we will create a How to Get the Actual Easter Date in JavaScript. This tutorial purpose is to teach you how to get the actual date for the easter day. This will tackle all the basic function that will display the easter date. I will provide a sample program to show the actual coding of this tutorial.

This tutorial is simple and easy to understand just follow the instruction I provided and you can do it without a problem. This program can be use to any system or application if you want to display some important like the easter day. I will give my best to provide you the easiest way of creating this program Display the Easter Date. So let's do the coding.

Before we get started:

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

Creating The Interface

This is where we will create a simple interface for our application. This code will display html forms and button for display easter date. To create this simply copy and write it into your text editor, then save it 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"

    >

    How to Get the Actual Easter Date in JavaScript</

    h3

    >
  16. <hr

    style

    =

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

    /

    >
  17. <div

    class

    =

    "col-md-3"

    >
  18. <form

    >
  19. <div

    class

    =

    "form-group"

    >
  20. <label

    >

    Enter a year</

    label

    >
  21. <input

    type

    =

    "number"

    id

    =

    "year"

    class

    =

    "form-control"

    /

    >
  22. </

    div

    >
  23. <center><button

    type

    =

    "button"

    onclick

    =

    "displayDate();"

    class

    =

    "btn btn-primary"

    >

    Get Date</

    button

    ></

    center>
  24. </

    form

    >
  25. </

    div

    >
  26. <div

    class

    =

    "col-md-6"

    >
  27. <div

    id

    =

    "result"

    ></

    div

    >
  28. </

    div

    >
  29. </

    div

    >
  30. <script

    src

    =

    "script.js"

    ></

    script

    >
  31. </

    body

    >
  32. </

    html

    >

Creating JavaScript Function

This is where the main function of the application is. This code will try you get the actual easter date base on the entered year. To do this just copy and write these block of codes inside the text editor and save it as script.js.
  1. let m=

    [

    "January"

    ,

    "February"

    ,

    "March"

    ,

    "April"

    ,

    "May"

    ,

    "June"

    ,

    "July"

    ,

    "August"

    ,

    "September"

    ,

    "October"

    ,

    "November"

    ,

    "December"

    ]

    ;


  2. function

    displayDate(

    )

    {
  3. let year=

    document.getElementById

    (

    'year'

    )

    .value

    ;

  4. if

    (

    year.length

    ==

    0

    )

    {
  5. alert(

    "Please enter something"

    )

    ;
  6. }

    else

    {
  7. let month=

    getEasterDate(

    year)

    [

    0

    ]

    ;
  8. let day=

    getEasterDate(

    year)

    [

    1

    ]

    ;
  9. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    "<h3>The easter date is: </h3><center><h2 class='text-primary'>"

    +

    m[

    month-

    1

    ]

    +

    " "

    +

    day+

    ", "

    +

    year+

    "</h2></center>"

    ;
  10. }
  11. }

  12. function

    getEasterDate(

    year)

    {
  13. let f =

    Math

    .floor

    ;
  14. let G =

    year %

    19

    ;
  15. let C =

    f(

    year /

    100

    )

    ;
  16. let H =

    (

    C -

    f(

    C /

    4

    )

    -

    f(

    (

    8

    *

    C +

    13

    )

    /

    25

    )

    +

    19

    *

    G +

    15

    )

    %

    30

    ;
  17. let I =

    H -

    f(

    H/

    28

    )

    *

    (

    1

    -

    f(

    29

    /

    (

    H +

    1

    )

    )

    *

    f(

    (

    21

    -

    G)

    /

    11

    )

    )

    ;
  18. let J =

    (

    year +

    f(

    year /

    4

    )

    +

    I +

    2

    -

    C +

    f(

    C /

    4

    )

    )

    %

    7

    ;
  19. let L =

    I -

    J;
  20. let month =

    3

    +

    f(

    (

    L +

    40

    )

    /

    44

    )

    ;
  21. let day =

    L +

    28

    -

    31

    *

    f(

    month /

    4

    )

    ;

  22. return

    [

    month,

    day]

    ;
  23. }

In the code above we a method that will calculate the date for the easter day, we will call this getEasterDate(). This function contains several algorithm that will calculate and target the actual easter date. Next method will be called displayDate(), this function purpose is to display the easter date after the calculation process is done.

Output:

How%20to%20Get%20the%20Actual%20Easter%20Date%20in%20JavaScript%201.png


The How to Get the Actual Easter Date in JavaScript source code that I provide can be download below. Please kindly click the download button.

There you have it we successfully created How to Get the Actual Easter Date in 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!

More Tutorials for JavaScript Language

JavaScript Tutorials


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

452,496

335,120

335,128

Top