Issue with "Execute Code" to Calculate Quiz Score
# 🤝help
s
Hi there, I followed Robert's video on creating an automated quiz bot. For this question only the main flow is relevant / where I'm having the issue. I'm trying to score the quiz where each time the correct answer is given, the user gets 1 point. I'm finding that the 2nd question and "execute code" isn't working. I've followed Robert's steps in the video. Is there an issue with the execute code in the screenshots? I can't see where it has gone wrong? Idea is the execute code will increase the quiz score by 1 https://cdn.discordapp.com/attachments/1241719335232339999/1241719335635124264/Screenshot_2024-05-19_214753.png?ex=664b38bf&is=6649e73f&hm=1d43588da7b8c1bf415e264e8baad408e9907c6e9c55522ff8fb924c365e2d49& https://cdn.discordapp.com/attachments/1241719335232339999/1241719336071204895/Screenshot_2024-05-19_214810.png?ex=664b38bf&is=6649e73f&hm=1edc63de679e164ec75a587e647312cb6679f8b70611ec90549a9e201ef5b1e7&
f
Hey there, It doesn't look like anything is wrong, but you are missing some options. You can do it easily by using
switch
Copy code
javascript
switch (workflow.Q2) {
    case '1996':
        workflow.QuizScore += 10;
        break;
    case '1998':
    case '1992':
    case '1994':
        workflow.QuizScore += 0;
        break;
    default:
        // Here you can handle an unexpected input. Could be that the user said 1995.
        break;
}
I can also help you a bit better if you can go in to more details about what the issue is. You are saying that its not working, but maybe you could explain that a bit more. Is it giving you errors or?
s
Hey @fresh-fireman-491 , Yeah it's a really strange one as I feel like I copied the steps in @bumpy-butcher-41910's video perfectly. The goal is for every correct answer in the workflow for the user to receive 1 point. Incorrect answers would just be 0 points. 64 questions and then an end score out of 64. Each question in stored in a variable. Eg: question 1 is Q1, question 2 is Q2 and so on... So so far I have Q1, Q2, Q3 and Q4 as the variables where I store the answer. What I'm finding is that for the first 4 questions (I've only done 4 so far to make sure I get it right) is that Q1, Q3 and Q4 all work correctly where they are attributing 1 point for a correct answer. Q2 though, it's not counting the correct answer as 1 point towards the score. The code is the same in the "execute code" card for Q2 and it is for Q3 and Q4 but for some reason it's not attirubuting 1 point when this question is answered correctly. I've been able to isolate it to Q2 by testing different answers and so it's definitely this part that isn't working. Does that make sense? I also tried your code but that didn't seem to help 😦 Any idea where I could be going wrong? Thanks so much
f
Try to rebuild Q2 from the start. From the single choice card to the execute code card
s
Yep I've done that a few times now haha... Just to see if it was a glitch
f
Hmm. Can you export your bot to me in a DM?
s
Yep sure thing, thank you! It's a really odd one
f
I wasn't able to get to it tonight, but I should be able to look at it tomorrow 🙂
s
Thanks mate 🙂
I've fixed it @fresh-fireman-491 ! The reason why was that the Q2 variable was a string variable instead of a number. Discovered that if the answer is a number then the variable type needs to be a number 🙂
f
Good work🦾
52 Views