• 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

Display Easter Date Using JavaScript

H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
73
Likes
169
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 1000 XP
In this code we will try to create Display Easter Date using JavaScript. The code will display the actual easter date base on the given year. This a user-friendly kind of code, feel free to modify it and use it as your coding reference. To learn more about this, just follow the steps below.

Getting started:

First you have to download bootstrap framework, 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"

    >

    Display Easter Date Using 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 Easter</

    button

    ></

    center

    >
  24. </

    form

    >
  25. </

    div

    >
  26. <div

    class

    =

    "col-md-6"

    >
  27. <div

    id

    =

    "result"

    ></

    div

    >
  28. </

    div

    >
  29. </

    div

    >
  30. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  31. </

    body

    >
  32. </

    html

    >

Creating the Script

This code contains the script of the application. The code will dynamically limit the password length when user click the button. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.
  1. var

    m=

    [

    "January"

    ,

    "February"

    ,

    "March"

    ,

    "April"

    ,

    "May"

    ,

    "June"

    ,

    "July"

    ,

    "August"

    ,

    "September"

    ,

    "October"

    ,

    "November"

    ,

    "December"

    ]

    ;


  2. function

    getEasterDate(

    year)

    {
  3. var

    f =

    Math

    .floor

    ;
  4. var

    G =

    year %

    19

    ;
  5. var

    C =

    f(

    year /

    100

    )

    ;
  6. var

    H =

    (

    C -

    f(

    C /

    4

    )

    -

    f(

    (

    8

    *

    C +

    13

    )

    /

    25

    )

    +

    19

    *

    G +

    15

    )

    %

    30

    ;
  7. var

    I =

    H -

    f(

    H/

    28

    )

    *

    (

    1

    -

    f(

    29

    /

    (

    H +

    1

    )

    )

    *

    f(

    (

    21

    -

    G)

    /

    11

    )

    )

    ;
  8. var

    J =

    (

    year +

    f(

    year /

    4

    )

    +

    I +

    2

    -

    C +

    f(

    C /

    4

    )

    )

    %

    7

    ;
  9. var

    L =

    I -

    J;
  10. var

    month =

    3

    +

    f(

    (

    L +

    40

    )

    /

    44

    )

    ;
  11. var

    day =

    L +

    28

    -

    31

    *

    f(

    month /

    4

    )

    ;

  12. return

    [

    month,

    day]

    ;
  13. }

  14. function

    displayDate(

    )

    {
  15. var

    year=

    document.getElementById

    (

    'year'

    )

    .value

    ;

  16. if

    (

    year.length

    ==

    0

    )

    {
  17. alert(

    "Please enter something"

    )

    ;
  18. }

    else

    {
  19. var

    month=

    getEasterDate(

    year)

    [

    0

    ]

    ;
  20. var

    day=

    getEasterDate(

    year)

    [

    1

    ]

    ;
  21. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    "<h4>Easter Date: </h4><center><h2 class='text-primary'>"

    +

    m[

    month-

    1

    ]

    +

    " "

    +

    day+

    ", "

    +

    year+

    "</h2></center>"

    ;
  22. }
  23. }

There you have it we successfully created a Display 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,503

355,786

355,795

Top