problem in execute code
# 👀feature-requests
t
i have a variable of password, i want the code to say if the password variable equals to 1234, print, correct, you can now ad changes to the materials, tools and equipments, otherwise if the possword is not 1234, print: wrong password, if this error occures one more time i will send a warning the the boss, the ask the user to type the password again, if the user puts the wrong message again, print: a warning has been sent to the boss, you wont be able to use the bot for the nest 5 minuts, and then make the user unable to use the bot for 5 minuts and set a timer, i am trying to put this code in an execute code
c
Hi there ! what is the current code your having issue with ?
f
When facing an issue i would recommend to use the proper Channel #1111009377525186570 for a higher chance of getting help.
t
const password = "1234"; function checkPassword() { const userPassword = prompt("Enter password: "); if (userPassword === password) { alert("Correct, you can now add changes to the materials, tools and equipments."); } else { alert("Wrong password."); const count = 1; do { userPassword = prompt("Enter password again: "); if (userPassword === password) { alert("Correct, you can now add changes to the materials, tools and equipments."); break; } else { alert("Wrong password. This error has occurred {} time(s).".format(count)); count++; } } while (count <= 2); if (count > 2) { alert("A warning has been sent to the boss. You will not be able to use the bot for the next 5 minutes."); setTimeout(() => { alert("You can now use the bot again."); }, 300000); } } } checkPassword();
c
@thousands-lighter-40109 Hi there, I see a bunch of errors with your code
I can point you in the right direction for now but I dont have the time to redo your whole code
t
i would apriciate any kind of help
c
JavaScript doesn't have a .format() method for strings like Python does. Instead, you can use template literals to interpolate values into strings.
You have declared userPassword and count as constants using the const keyword. This means that their values cannot be reassigned later in the code. This will throw an error when you try to reassign the value of userPassword and count in the loop. You should change const to let for these variables.
also, If you're running this code outside of a browser, prompt and alert will not be defined.
afaik, Botpress does not support alert or prompt since it's not a browser environment.
try this code 🙂
`const password = "1234"; async function checkPassword(bp, event, userPassword) { // Retrieve the count from the user's temporary storage let count = event.state.session.passwordAttempts || 0; if (userPassword === password) { await bp.events.replyToEvent(event, { type: 'text', text: "Correct, you can now add changes to the materials, tools and equipments." }); } else { count++; if (count <= 2) { await bp.events.replyToEvent(event, { type: 'text', text:
Wrong password. This error has occurred ${count} time(s).
}); } else { await bp.events.replyToEvent(event, { type: 'text', text: "A warning has been sent to the boss. You will not be able to use the bot for the next 5 minutes." }); // If you want to introduce a delay, you might need to use other methods or custom integrations } // Store the updated count in the user's temporary storage event.state.session.passwordAttempts = count; } }`
t
thank you for your help brother
p
Hi, a quick question. Is the code you've provided for use in botpress studio? I ask because I can see that you've used the bp object. Do we have access to that in an execute code card?
5 Views