Javascript newbie - what is wrong with this statement?
-
if (passed ==true && (isbn.value.length != "13" || isbn.value.length != "10")) { alert("The ISBN can only be 10 or 13 digits long."); passed = false; ...show more
-
Answer:
if (passed && ((isbn.value.length = 13 || isbn.value.length = 10) == false)) 1) length is a number, not a string. 2) "boolean value == true" is called a pleonasm - the interpreter has to evaluate passed, then it has to evaluate (passed == true), which is the same value as passed. It's wasted effort. 3) You can drop passed altogether, unless it's usually false - just check for the length (even if passed is usually false, executing the code doesn't cost much): if (!(isbn.value.length = 13 || isbn.value.length = 10)) is only 3 evaluations.
Q2YQARBIKQYWGHQPCAXCIHCIHY at Yahoo! Answers Visit the source
Other answers
well, first of all, what are you trying to do. don't worry I'll help you noob.
Kit K
Related Q & A:
- What's wrong with this PHP Twitter API POST?Best solution by Stack Overflow
- What is wrong with this Laravel 5 response?Best solution by Stack Overflow
- What is a basic policy statement?Best solution by answers.yahoo.com
- What is a great thesis statement about homework?Best solution by Yahoo! Answers
- What exactly is a thesis statement?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.