Learning programming is new to me, so please bear with me.
I am currently utilizing Informer, a reporting website that retrieves data from Datatel, a unidata database.
My current task involves working on a computed column that only accepts Javascript and no other language.
The objective of the column is as follows:
"If classes are scheduled for Mon, Tue, Wed, Thur, and Fri then display Mon-Fri"
In simpler terms, if classes take place every weekday, I want to condense the output to simply say "Mon-Fri" instead of listing out each individual day.
However, the code I have written is not functioning as intended. It displays "Mon-Fri" for every class, even those that do not meet on those days.
Here is the code snippet that is not yielding the desired results:
//declare variables
var mon = secmonday[1];
var tue = sectuesday[1];
var wed = secwednesday[1];
var thur = secthursday[1];
var fri = secfriday[1];
var formatDays = "";
//if monday through friday = Y (Y being the value in the database)
//then format with a hyphen between days
if ((mon && tue && wed && thur && fri) == "Y");
{
formatDays = "Mon-Fri";
}
else
{
// if any of the days fields are empty then do not display formatDays
//instead leave it blank
if ((mon || tue || wed || thur || fri) == null);
}
formatDays = mon + tue + wed + thur + fri;
Could you please point out what I am doing wrong? Your assistance would be greatly appreciated. Thank you!
Update: I managed to find a solution to the issue:
//define variables
var days = courseSections6_csmdaysk;
var output = "";
var formatDays = "Mon-Fri";
//removes whitespace within data
var formatBlank = days.replace(/\s+/g, '');
//if all days are present then display Mon-Fri
if (days == "M T W TH F")
{
output = formatDays;
}
else
{
output = formatBlank;
}
output