Herossandro
Critical Infrastructure Pentester
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
In this tutorial we will create a Simple Leap Year Checker using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. This code can be used as your calculator to any mathematical problem. So Let's do the coding...
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. This code will render application and display the form. To create this just write these block of code inside the text editor and save this as index.html.
Creating the Script
This code contains the script of the application. This code will check whether the year has a leap year. To do this just copy write the code as shown below inside the text editor and save it inside the js directory as script.js.
There you have it we successfully created a Simple Leap Year Checker using JavaScript. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Download
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. This code will render application and display the form. To create this just write these block of code inside the text editor and save this as index.html.
- <!DOCTYPE html>
- <html
lang
=
"en"
>
- <head
>
- <meta
charset
=
"UTF-8"
name
=
"viewport"
content
=
"width=device-width, initial-scale=1"
/
>
- <link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"css/bootstrap.css"
/
>
- </
head
>
- <body
>
- <nav class
=
"navbar navbar-default"
>
- <div
class
=
"container-fluid"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
JavaScript - Simple Leap Year Checker</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6"
>
- <div
class
=
"form-group"
>
- <input
type
=
"number"
id
=
"year"
class
=
"form-control"
placeholder=
"Enter a year here..."
/
>
- </
div
>
- <center
><button
class
=
"btn btn-primary"
onclick
=
"yearCheck(this);"
id
=
"check"
>
Check</
button
></
center
>
- <center
><button
class
=
"btn btn-success"
onclick
=
"reset(this);"
style
=
"display:none;"
id
=
"reset"
>
Reset</
button
></
center
>
- <br
/
>
- <div
id
=
"result"
></
div
>
- </
div
>
- </
div
>
- <script
src
=
"js/script.js"
></
script
>
- </
body
>
- </
html
>
Creating the Script
This code contains the script of the application. This code will check whether the year has a leap year. To do this just copy write the code as shown below inside the text editor and save it inside the js directory as script.js.
- function
yearCheck(
btn)
{
- var
year =
document.getElementById
(
'year'
)
.value
;
- if
(
year ==
""
)
{
- document.getElementById
(
'result'
)
.innerHTML
=
"<center><label class='text-danger'>Please enter a valid year</label></center>"
;
- }
else
{
- if
(
!
(
year %
4
)
&&
(
year %
100
)
||
!
(
year %
400
)
)
{
- document.getElementById
(
"result"
)
.innerHTML
=
"<div class='alert alert-success' style='text-align:center;'>Year <label class='text-primary'>"
+
year+
"</label> is a LEAP YEAR</div>"
;
- }
else
{
- document.getElementById
(
"result"
)
.innerHTML
=
"<div class='alert alert-warning' style='text-align:center;'>Year <label class='text-danger'>"
+
year+
"</label> is a NOT LEAP YEAR</div>"
;
- }
- btn.style
.display
=
'none'
;
- document.getElementById
(
'reset'
)
.style
.display
=
''
;
- document.getElementById
(
'year'
)
.setAttribute
(
'readonly'
,
'readonly'
)
;
- }
- }
- function
reset(
btn)
{
- document.getElementById
(
'year'
)
.value
=
""
;
- document.getElementById
(
"result"
)
.innerHTML
=
""
;
- btn.style
.display
=
'none'
;
- document.getElementById
(
'check'
)
.style
.display
=
''
;
- document.getElementById
(
'year'
)
.removeAttribute
(
'readonly'
)
;
- }
There you have it we successfully created a Simple Leap Year Checker using JavaScript. I hope that this very 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 hidden text.