I think CraziFuzzy does have the root of what's causing that output, but there are some other things you might want to fix in your script,
(typeof(p9.value || p10.value)=='undefined')
will not work, anything that can be logical or'ed tends to be boolean by its very nature. You have to split that into
(typeof(p9.value) == 'undefined' || typeof(p10.value)=='undefined')
There is also no definition for result when a < 0 to return.