Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <html lang="en">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Leap Years Between A Range</title>
    <!-- Google Fonts -->
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
    <div class="container">
      <div class="row">
        <div class="input-wrapper">
          <label for="start-year">Start Year:</label>
          <input type="number" value="1900" id="start-year" />
        <div class="input-wrapper">
          <label for="end-year">End Year:</label>
          <input type="number" value="2022" id="end-year" />
      <button id="get-leap-years">Get Leap Years</button>
      <div id="result"></div>
    <!-- Script -->
    <script src="script.js"></script>


                * {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
body {
  background-color: #f5c431;
.container {
  background-color: #ffffff;
  width: 90vw;
  max-width: 37.5em;
  position: absolute;
  padding: 3em 1.8em;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
  border-radius: 8px;
  box-shadow: 0 1em 2em rgba(112, 90, 23, 0.3);
.row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 1.8em;
.input-wrapper {
  width: 100%;
label {
  font-weight: 600;
  color: #000533;
input {
  display: block;
  width: 100%;
  font-size: 1.3em;
  color: #363a5f;
  margin-top: 0.5em;
  padding: 0.25em 0.5em;
  border: none;
  outline: none;
  border-bottom: 2px solid #000533;
input:focus {
  border-bottom-color: #f5c431;
button {
  font-size: 1.25em;
  margin: 1.25em 0 1.75em 0;
  width: 100%;
  background-color: #f5c431;
  color: #000533;
  border: none;
  padding: 0.6em 0;
  border-radius: 1.25em;
#result span {
  display: block;
  line-height: 2;
  text-align: justify;
  color: #363a5f;
  margin-top: 1em;
#result b {
  font-size: 1.2em;
  display: block;
  line-height: 1.4em;
  font-weight: 600;
  color: #000533;
  text-align: center;


                //Initial References
let result = document.getElementById("result");
let btn = document.getElementById("get-leap-years");

//Get Leap years when the button is clicked
btn.addEventListener("click", () => {
  //Get values from the input fields
  //Number() converts string value to number
  let startYear = Number(document.getElementById("start-year").value);
  let endYear = Number(document.getElementById("end-year").value);

  //If both start and end year are invalid
  if (
    (startYear < 1582 || startYear > 2999) &&
    (endYear < 1582 || endYear > 2999)
  ) {
    result.innerHTML = `<b>The start year and end year should be greater than 1581 and less than 3000.</b>`;

  //If start year is greater than end year
  else if (startYear > endYear) {
    result.innerHTML = `<b>End year should be greater than the start year.</b>`;

  //If start year is invalid
  else if (startYear < 1582 || startYear > 2999) {
    result.innerHTML = `<b>The start year should be greater than 1581 and less than 3000.</b>`;

  //If end year is invalid
  else if (endYear < 1582 || endYear > 2999) {
    result.innerHTML = `<b>The end year should be greater than 1581 and less than 3000.</b>`;

  //If both start and end years are valid
  else {
    //Empty array to store the leap years
    let leapYears = [];
    for (let i = startYear; i <= endYear; i++) {
      //Determine if a year is a leap year
      //If true push it into leapYears[]

      if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
    //Display leap years in result div
    //toString() returns a string with comma seperated values
    //Use combo of split() and join() to replace ',' with ', '
    result.innerHTML = `<b>There are ${
    } leap years between ${startYear} & ${endYear}.</b><span>${leapYears
      .join(", ")}</span>`;