Searching for one of many substrings in two different fields

I'm trying to write some code that checks two fields for specific substrings in order to categorize them and return in a 3rd field the name of the category the info should fall into. I have approached this from multiple different directions but cannot seem to get it to work. The names of fields and keywords used have been changed but the general principle of what I am trying to achieve is the same.

In this example the input fields would be "Channel" and "Network" and I want the third field "Category" to be filled out automatically based on the two inputs.

(function() {
'use strict';

// Function to check for keywords in two specific Kintone fields
function checkKeywords(record) {

   // Define the keywords and their corresponding outputs
   // Everything below is searched in lowercase 
   const keywords = {
       "espn":"Sports",
       "sports":"Sports",
       "abc":"News",
       "cbs":"News",
       "pbs":function(Channel,Network){
           let channelPlusNetwork = concat(Network,"--",Channel).toLowerCase();
           let conditionA = channelPlusNetwork.includes("pbs") && channelPlusNetwork.includes("kids");
           let conditionB = channelPlusNetwork.includes("pbs kids");
           return conditionA || conditionB ? "Children's TV":"Public";
       },
       "hbo":"Premium",
       };
   // Add more keywords and outputs as needed

}

// Get values of "Channel" and "Network" fields from the record
const channel = record.Channel.value.toLowerCase();
const network = record.Network.value.toLowerCase();
let combinedText = concat(network,"--",channel);

// Check if either field contains any of the keywords
for (const keyword in combinedText) {
if (channel.includes(keyword) || network.includes(keyword)) {
// Return the output corresponding to the matched keyword
return combinedText[keyword];
}
var finalOutput = combinedText[keyword];
}

// Handles both record creation and editing scenarios for channel field changes
var changeEvents = [
'app.record.create.change.Channel',
'app.record.edit.change.Channel'
];
kintone.events.on(changeEvents, function(event) {
var finalOutput = checkKeywords(event.record.Channel.value);
if (finalOutput !== null) {
event.record.Category.value = finalOutput.toString();
}
return event;
});

// Handles both record creation and editing scenarios for submitting records
var submitEvents = [
'app.record.create.submit',
'app.record.edit.submit'
];
kintone.events.on(submitEvents, function(event) {
var finalOutput = checkKeywords(event.record.Channel.value);
if (finalOutput !== null) {
event.record.Category.value = finalOutput.toString();
}
return event;
});
})();

Please let me know what I am doing wrong and how I can fix it. I have tried approaching it from this direction, using if/else statements, and a switch function but for some reason I can't get it to populate the Category field.

Hello @kevinrotenkolber

It appears there are several structural issues and logical errors in your code, including misuse of variables and functions, as well as scoping and execution issues, that need to be addressed to ensure it operates as intended.

I recommend debugging each line to identify and correct these problems.
If you encounter any errors during debugging that you cannot resolve, please share them here for further assistance.