Regex won't work?


#1

Can anyone explain to me why my expression doesnt work?
It wont let me interprete the prompt("lol"); statement. Can anyone explain why?


#2

Try it by changing your

var allowedNumbers = /[3-18]/;

into

var allowedNumbers = [3,18];

#3

nvm, it works! :smiley:
But I have another problem now, and it is my if statement that i try to run. I get no output.


#4

But the thing with your expression [3,18] is not the same thing as [3-18]. I want to match the numbers 3,4,5,6,...,18. With your expression it will only look for the numbers 3 and 18.


#5

@codewhiz09204,
You will have to use the IF condition

allowNumber[0] < guess && guess < allowedNumber[1]

using the less than comparison operator
together with the logical and operator
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators

[3,18] is an Array with 2 Elements
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
if you look in the left-hand column under the =header= Methods
you see all predefined functions of the Array-prototype


#6

Honetly the code should work as I wrote it, but I dont know why?


#7

@codewhiz09204
Then give the FULL HTML code
and the FULL script code
maybe i can be of help


#8

Thank you very helping me out! I did a lazy solution by doing the following code: /[3,4,5,6,...,18]/