Basic JavaScript Help
# 🤝help
f
Hey guys I need some help with some pretty basic javascript, however, I’m not a coder myself but I think it could be solved pretty easily. What I want to do I am making a quiz to walk people through to test if they are eligible for my service/product. I’m at a part of the workflow where I already know how many employees the company have (variable “employeeNumber”) but I need to see if they are all part-time. What I want to happen I want to run a code that does 3 simple things 1: Check if numberPartTime >= employeeNumber 2: Split the outcome into two sections, one for those where all their employees are part-time and say something like “sorry can’t help” and end, and another where the number of employees are greater than parttime and able to send them to the next question 3: Given the new information I want to create and record a new variable called “relevantEmployeeNumber” which is employeeNumber - numberPartTime Not really sure how to make this work but would love some feedback, feel free to ask for more details. Thanks 🙂
a
hey @fancy-monkey-19130, chat GPT is really great for writing code for situations like this https://chat.openai.com/. I fed your post to it and got this:
Copy code
js
// Step 1: Check if numberPartTime >= employeeNumber
const numberPartTime = 10;
const employeeNumber = 15;

if (numberPartTime >= employeeNumber) {
  console.log("Sorry, can't help.");
} else {
  // Step 2: Split the outcome based on employee type
  const partTimeEmployees = numberPartTime;
  const fullTimeEmployees = employeeNumber - numberPartTime;
  
  console.log("Part-time employees:", partTimeEmployees);
  console.log("Full-time employees:", fullTimeEmployees);
  
  // Step 3: Create and record a new variable called relevantEmployeeNumber
  const relevantEmployeeNumber = employeeNumber - numberPartTime;
  console.log("Relevant employee number:", relevantEmployeeNumber);
}
Which is a pretty good start! You'll still need to make some small changes like: * Changing
numberPartTime
and
employeeNumber
to be equal to the variables from your flow * Instead of using
console.log
to send messages, you can assign
workflow.nextMsg
to be what the bot says.
f
Unforrunally didn't work like hoped. I will keep trying tho
@acceptable-kangaroo-64719 Is it possible to co-work on a bot with a friend?
a
you can invite collaborators to your workspace, yes
f
Awsome! How would I do that?
a
click the gear icon then go to collaborators
f
Awsome thanks. I am unable to have the script run so asking a friend
One more question @acceptable-kangaroo-64719 When I solve the script part, aka get two different answers based on if they are eligible, how do I split it into two outcomes? I need one outcome to end the chat and one to go on to next question. I only have one dot to draw from right now. I have a feeling it is solved with the flow logic but not sure how
Finally got the code to work! I love botpress but jesus I hate JS! Last problem (hopefully) how do I split up the flow to send people different ways based on their nextMsg? I have a feeling it is solved with the flow logic but not sure how
a
yes, you can use expression transitions (with more JS) to split up based on variables
2 Views