0

Switch case statement

so i am building a bot for discord in javascript and i want to make it so that everytime a run a command line /unkown1563 that the bot will reply back with one of 10 options but everytime i start it up it always runs only one of the lines of codes and never swtitches between the other ones can anyone help me fix the issue thx. code is proved below and if you need anything more information please contact me here var prefix='/' var x=Math.floor(Math.random(1,100)*10); if(message.content.startsWith(prefix + 'Unknown1563')) { switch (x) { case (x=0): message.channel.sendMessage('testing case 0'); break; case (x=1): message.channel.sendMessage('testing case 1'); break; case (x=2): message.channel.sendMessage('testing case 2'); break; case (x=3): message.channel.sendMessage('testing case 3'); break; case (x=4): message.channel.sendMessage('testing case 4'); break; case (x=5): message.channel.sendMessage('testing case 5'); break; case (x=6): message.channel.sendMessage('testing case 6'); break; case (x=7): message.channel.sendMessage('testing case 7'); break; case (x=8): message.channel.sendMessage('testing case 8'); break; case (x=9): message.channel.sendMessage('testing case 9'); break; default: message.channel.sendMessage('default message'); }} for testing change all (message.channel.sendMessage) to document.write and remove the if statement

16th Nov 2017, 3:42 AM
Wilde Night
Wilde Night - avatar
6 Respostas
+ 1
Try this maybe? switch(x) { case 0: // code here break; case 1: // code here break; default: // code here } Hth, cmiiw
16th Nov 2017, 5:17 AM
Ipang
+ 1
Try to verify that the string begins with "/Unknown1563", also check the random number, is it really always between 0 and 10, or if your way of switch works, try with case(x==n) instead of (x=n).
17th Nov 2017, 1:42 AM
Ipang
17th Nov 2017, 1:52 AM
Ipang
0
i did that once it gave me a random case and stuck with it
16th Nov 2017, 5:40 PM
Wilde Night
Wilde Night - avatar
0
see x will run everytime i do the command line and will alternate between 0-10 but for some reason its not alternating between the 0-10 and just picking one number and ik my var x=math statement works
16th Nov 2017, 7:00 PM
Wilde Night
Wilde Night - avatar
0
anything i need to run x everytime i put in a command line but i just dont know how to apply it to my switch statement
16th Nov 2017, 7:01 PM
Wilde Night
Wilde Night - avatar