If you're searching for a job, chances are that the company might ask you to do a code test. If you have to do so, you should take into account a few basic points that sadly I see quite often reviewing candidate code tests:
- Focus on the main problem to solve: Almost all code tests have a main point to solve/code/represent. Focus on that first instead of on lesser details, and never ever skip coding this part "because of lack of time".
If you can't complete everything, it is better to have finished the important parts at least.
Also respect time limits if they are present, it is better to send an incomplete code within time and then ask for extra time, than sending something 2 hours late.
- Don't do hacks: Don't do any hack except you're sure it is absolutely necessary. If the algorithm you choose doesn't "fit" or you find that it was not the correct one, don't do dirty things to force it to work.
Companies rarely ask for hacks in code tests, it is usually more of a sign that you are doing it wrong.
- Showcase your coding skills: You are applying for a job, not showing a piece of code to your friend. Comments are welcome and commented out testing code is acceptable, but if almost half of your code is commented without even notes of why, it looks very chaotic.
Same goes for things like variable, method or class naming.
- Be sincere: If a code test is too much, maybe doing only the part you're able to, or "giving up" will allow you to do another one more suited to your skills. But if for example you're requested to use object orientation and you fake it (by having just one object without any inheritance) you have many points to be directly discarded.
As a side note, you should be prepared to be judged as you described yourself in your CV and interviews. If you said you're a crack, you shall be asked to perform as that in the code test ;)