Remove “use strict”; from all of the functions (except for the iife function)
Put all of the code inside the iife function, just below the "use strict"; line
JSLint tends to have two main types of issues with code. One is layout issues, and the other is syntax issues.
After you add that code in to the iife function, you’ll need to indent all of the code, which is another layout issue. That’s easy to fix with JavaScript Beautifier
The code can then be copied from there to JSLint, and you’ll only have mostly syntax issues to worry about.
I and most programmers use a special coding program to make my life easier. Mine has JSLint built inside of it which warns me immediately when something is wrong. Programming then becomes a mini-game of making any errors go away as fast as you can.
There’s also a programming technique called TDD (Test Driven Development) or BDD (Behaviour Driven Development) where you:
create a test that expects a certain value from a function when you give is a certain input
write the code that makes that test pass
without changing the apparent behaviour of the code, refactor and adjust the code to make it easier to work with
The test gives an error, writing code makes the test pass, and refactoring improves the code.
That is the heartbeat of TDD, and it’s a tight little cycle that lasts no longer than a minute or two.
It knows that playButton3 isn’t used, at least by the JavaScript code that you gave it, because it is pretty smart and can figure out that nothing in that code calls the playButton3 function.
Yes there is an inline event that uses it, so as long as you know that it is used somewhere, it’s fine to ignore that message.
A simple solution to that though is to use JavaScript instead to assign the function to the element, by putting this code below the function.
Check yourself to see if the function is being used on any HTML inline event attributes. They quite likely will be.
If they are being used there, then the code should still work.
We can though go through moving them out of the inline event attributes down to proper scripting code if you want.
You’ll find that http://jsbeautifier.org/ is useful to pre-process the code when you have a large amount of code to check.
One issue though is in terms of anonymous functions, which are functions that have no name.
JSBeautifer removes the space before the () when there is no name
The difference there is that the functions are globally accessible functions. The linter doesn’t know if other code will be calling global functions, and so doesn’t warn about that.
When the code is inside a function, such as the iife which protects the global namespace, the functions can’t be accessed from anywhere else except from inside of the iife, therefore JSLint knows for sure that nothing else can call those functions.
You want to be warned about potential problems like that, instead of just ignoring them.