# Javascript code is not running

**URL:** <https://community.glideapps.com/t/javascript-code-is-not-running/68577>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [December 11, 2023, 1:39pm UTC](https://community.glideapps.com/t/javascript-code-is-not-running/68577 "2023-12-11T13:39:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bunyod](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bunyod/32/68110_2.png) [@Bunyod](https://community.glideapps.com/u/Bunyod)\
**Post date:** [December 11, 2023, 1:39pm UTC](https://community.glideapps.com/t/javascript-code-is-not-running/68577/1 "2023-12-11T13:39:20Z")

</div>

I’m using Javascript column but it is not giving result in Glide, already tested in compiler. It works.

I’m on free version of Glide, if this is an issue, which plan should get?

The purpose is, to get selected amout of monthes starting from month selected.

For example. 6 monthes from November 2023

The result should be. “November 2023, December 2023, January 2024, February 2024, March 2024, April 2024”

**The code**

```function
  const monthNames = [
    "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"
  ];

  let startIndex = monthNames.indexOf(startMonth);
  let currentYear = startYear;
  let resultMonths = [];

  for (let i = 0; i < monthsCount; i++) {
    let currentIndex = (startIndex + i) % 12;
    // Increment the year when the month wraps around to January
    if (currentIndex === 0 && i !== 0) {
      currentYear++;
    }
    resultMonths.push(monthNames[currentIndex] + " " + currentYear);
  }

  return resultMonths.join(", ");
}

// Example usage:
const startMonth = "November"; // Starting month
const startYear = 2023; // Starting year
const monthsCount = 6; // Number of months to list

const result = listMonths(startMonth, startYear, monthsCount);
console.log(result); // Correct Output: "November 2023, December 2023, January 2024, February 2024, March 2024, April 2024"

```

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [December 11, 2023, 1:45pm UTC](https://community.glideapps.com/t/javascript-code-is-not-running/68577/2 "2023-12-11T13:45:12Z")

</div>

I haven’t tried your code but probably because you’re not returning anything. Change your last line to a return instead of console.log

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [December 11, 2023, 1:54pm UTC](https://community.glideapps.com/t/javascript-code-is-not-running/68577/3 "2023-12-11T13:54:18Z")

</div>

Issues:

- You call a function that doesn’t exist (perhaps you didn’t share the entire code snippet?)
- You don’t return anything.

Here is a working version:

```auto
function listMonths(startMonth, startYear, monthsCount) {
  const monthNames = [
    "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"
  ];

  let startIndex = monthNames.indexOf(startMonth);
  let currentYear = startYear;
  let resultMonths = [];

  for (let i = 0; i < monthsCount; i++) {
    let currentIndex = (startIndex + i) % 12;
    // Increment the year when the month wraps around to January
    if (currentIndex === 0 && i !== 0) {
      currentYear++;
    }
    resultMonths.push(monthNames[currentIndex] + " " + currentYear);
  }

  return resultMonths.join(", ");
}

const startMonth = "November"; // Starting month
const startYear = 2023; // Starting year
const monthsCount = 6; // Number of months to list

return listMonths(startMonth, startYear, monthsCount);

```

---

<div class="post-metadata">

**Author:** ![Bunyod](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bunyod/32/68110_2.png) [@Bunyod](https://community.glideapps.com/u/Bunyod)\
**Post date:** [December 11, 2023, 5:50pm UTC](https://community.glideapps.com/t/javascript-code-is-not-running/68577/4 "2023-12-11T17:50:01Z")

</div>

Thank you Darren the code is working well 🥳🕶

---

<div class="post-metadata">

**Author:** ![Bunyod](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bunyod/32/68110_2.png) [@Bunyod](https://community.glideapps.com/u/Bunyod)\
**Post date:** [December 11, 2023, 5:53pm UTC](https://community.glideapps.com/t/javascript-code-is-not-running/68577/5 "2023-12-11T17:53:06Z")

</div>

Thanks Eric

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [December 18, 2023, 5:53pm UTC](https://community.glideapps.com/t/javascript-code-is-not-running/68577/6 "2023-12-18T17:53:49Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
