Hi, I’m trying to replicate an spreadsheet IF/ELSE formula in Glide, that will combine three columns into a single text column. For clarification, I’ve put a picture of those 3 columns, and a text column on the right to show the desired output.
// Assuming you have three columns: staticsRemaining, videosRemaining, otherContentsRemaining
function remainingContentMessage(staticsRemaining, videosRemaining, otherContentsRemaining) {
let result = [];
// Check statics
if (staticsRemaining > 0) {
result.push(staticsRemaining + " " + (staticsRemaining === 1 ? "static" : "statics"));
}
// Check videos
if (videosRemaining > 0) {
result.push(videosRemaining + " " + (videosRemaining === 1 ? "video" : "videos"));
}
// Check other contents
if (otherContentsRemaining > 0) {
result.push(
otherContentsRemaining + " " + (otherContentsRemaining === 1 ? "other content" : "other contents")
);
}
// Construct final message based on conditions
if (result.length === 0) {
return "No content remaining";
} else if (result.length === 1) {
return result[0] + " remaining";
} else {
return result.slice(0, -1).join(", ") + " and " + result.slice(-1) + " remaining";
}
}
// Example usage
const staticsRemaining = 3;
const videosRemaining = 1;
const otherContentsRemaining = 0;
const message = remainingContentMessage(staticsRemaining, videosRemaining, otherContentsRemaining);
console.log(message); // Output: "3 statics and 1 video remaining"