Reputation: 65
I am trying to run my JavaScript code on google scripts and it is having some trouble running at times. I was wondering if there was anything wrong with my code and how i could get this to run? It's a very simple calculation.
function myFunction() {
var heavy = 10;
var light = 45;
var petro = 55;
var heavyoil = 0;
var lightoil = 0;
var petrooil = 0;
var counter = 0;
var equals = true;
while (equals == true) {
while (heavyoil >= 40) {
heavyoil -= 40;
lightoil += 30;
}
while (lightoil >= 30) {
lightoil -= 30;
petrooil += 20;
}
heavyoil += heavy;
lightoil += light;
petrooil += petro;
counter++;
if (heavyoil == 0 && lightoil == 0) {
equals = false;
}
}
}
Upvotes: 0
Views: 32
Reputation: 1008
You're probably running into an infinite loop issue.
Google Scripts allows you to have the script ran automatically after a configurable amount of time (e.g. every 5 min). Try using that automation option.
To run a script at a time or times you designate:
From the Script Editor, choose Resources > Current project's triggers. You see a panel with the message No triggers set up. Click here to add one now.
Click the link that says No triggers set up. Click here to add one now.
Under Run, select the function you want executed on schedule.
Under Events, select Time-driven.
On the first drop-down list that appears, select Week timer, Day timer, Hour timer, or Minutes timer, or Specific date and time. Depending on which you select, you see one or more additional lists or a text box.
To test the trigger and your function, you might want to pick a short duration so that you can see the execution without having to wait hours or days.
-If you picked Week timer, select a day of the week and time of day.
-If you picked Day timer, select an hour. If you picked Hour timer, select an interval of hours. If you picked Minutes timer, select aninterval of minutes.
-If you picked Specific date and time, enter a date in YYYY-MM-DD HH:MM format.
Click Save.
To ensure that the script runs at the correct time for a particular time zone, click File > Properties, select a time zone, and click Save.
Upvotes: 0
Reputation: 1401
more than likely due to the issues Google hosted libraries was having today. We were getting 503s, CORS policy issues, as well as all hosted libraries resources behind captchas all the sudden. See article: https://thenextweb.com/2017/09/12/google-down-gmail-youtube-maps/#.tnw_D3G3c5M3
Upvotes: 1