So I have always wanted to do something like this, but never knew how to use an undefined natural variable (e.g. 1, 2, 3, 4, 5 …)
I want something like this:
if($("#container").width() == 400*n) {
//do something
}
In which case n can be any natural cardinal number (and preferably not zero). How do you define n?
JavaScript does not solve equations with unknowns for you; at any given time, a variable always holds a specific value.
So, what you seem to want to do (if I understand your question correctly) is not possible. Instead, you need to solve the equation you gave yourself:
can be restated as
Now, since you require
nto be an integer, the above statement means that dividing$("#container").width()will yield a whole number. The requirement “dividing a by x yields a whole number” is usually expressed with the modulo operator (%in JavaScript) asa % x == 0. Thus you end up with: