admin管理员组文章数量:1026989
I was working on a simple programming exercise my teacher gave us, and I noticed several times that in Javascript, I have to divide a number by 1, otherwise it will return a ridiculous value. Any explanations? I have a jsfiddle /
var widthrand=Math.floor(Math.random()*widthRange);
width=widthrand + document.getElementById('width').value/1;
If you look at line 22, and take out the divide by 1, and click generate, it will return ridiculous lengths Thanks
I was working on a simple programming exercise my teacher gave us, and I noticed several times that in Javascript, I have to divide a number by 1, otherwise it will return a ridiculous value. Any explanations? I have a jsfiddle http://jsfiddle/TpNay/1/
var widthrand=Math.floor(Math.random()*widthRange);
width=widthrand + document.getElementById('width').value/1;
If you look at line 22, and take out the divide by 1, and click generate, it will return ridiculous lengths Thanks
Share Improve this question edited Feb 15, 2013 at 1:38 John Conde 220k99 gold badges463 silver badges502 bronze badges asked Feb 15, 2013 at 1:20 scrblnrd3scrblnrd3 7,4349 gold badges36 silver badges65 bronze badges1 Answer
Reset to default 11It makes JavaScript type juggle forcing the value of document.getElementById('width').value
to bee numeric.
A better way to do it would be parseInt(document.getElementById('width').value, 10)
I was working on a simple programming exercise my teacher gave us, and I noticed several times that in Javascript, I have to divide a number by 1, otherwise it will return a ridiculous value. Any explanations? I have a jsfiddle /
var widthrand=Math.floor(Math.random()*widthRange);
width=widthrand + document.getElementById('width').value/1;
If you look at line 22, and take out the divide by 1, and click generate, it will return ridiculous lengths Thanks
I was working on a simple programming exercise my teacher gave us, and I noticed several times that in Javascript, I have to divide a number by 1, otherwise it will return a ridiculous value. Any explanations? I have a jsfiddle http://jsfiddle/TpNay/1/
var widthrand=Math.floor(Math.random()*widthRange);
width=widthrand + document.getElementById('width').value/1;
If you look at line 22, and take out the divide by 1, and click generate, it will return ridiculous lengths Thanks
Share Improve this question edited Feb 15, 2013 at 1:38 John Conde 220k99 gold badges463 silver badges502 bronze badges asked Feb 15, 2013 at 1:20 scrblnrd3scrblnrd3 7,4349 gold badges36 silver badges65 bronze badges1 Answer
Reset to default 11It makes JavaScript type juggle forcing the value of document.getElementById('width').value
to bee numeric.
A better way to do it would be parseInt(document.getElementById('width').value, 10)
本文标签: htmlPurpose of dividing by 1 javascriptStack Overflow
版权声明:本文标题:html - Purpose of dividing by 1 javascript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745658043a2161715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论