Similarly, on this next line of code,
I have something that's syntactically correct.
And actually, it's logically correct.
But it's just kind of silly.
Why would you ever check if something is greater than 65 or greater than 18?
There's really no need to check both conditions, because if you know you're
greater than 65, you're pretty much guaranteed that you're also over 18.
This is why,
when you're writing your code, you wanna just stop every once in a while and
make sure you're double checking each line as to what it's actually doing.
Another very common source of frustration and
sometimes outright anger with people is the + operator.
You need to remember that the + works differently depending upon
the type of variables.
So 5 + 5, oh.
Well that evaluates to 10.
But 5 + 5, two strings.
That's going to concatenate.
It's not going to add it.
It's gonna concatenate it and give you 55.
So what happens if you have a number with a string and you have that + operator?
Well, in that case, even if it only sees a single string,
even if there were 18 things, +, +, +, as soon as it sees a single string,
it says, oh, this is a concatenation operator not an addition.
This isn't always bad.
Sometimes you want to concatenate strings and variables together.
Sometimes you might wanna have a variable right here, such as source,
that says, oh, do you know what?
I wanna grab a new source file.
How can I do that?
Because I need to use the exact words, url, and the parentheses.
And over here, I need it to end in another parentheses.
Now, who knows what img.src is?
I have a pretty good idea that img.src is an element out there,
where can grab the source.
But this is a great and very useful to you example of how you can combine strings,
plus the variables, plus strings to create a new string.
Next, let's talk about nesting.
When you start nesting,
it's very important that your else statements match the appropriate if.
You also want to make sure that you never include semicolons inside the if itself.
Let me show you an example.
Right here, I have if (age < 18); alert("Too young!");.
This isn't going to do what you expect.
If you remember, computers ignore indentation.
So, while it looks really good and
it looks like you're saying, if this is true, do that.
It's not going to work.
This semi-colon right here, eh, it's really bad.
It counts as a statement.
So what you're really saying right here is, if age is less than 18, nothing.
And then it will immediately go down to the next line.
It's always going to say too young.