I am trying to understand what I’m doing wrong.
If penX and penY = 1, I get expected results.
If penX and penY = 10, I get un-expected results.
[code=php]
<html>
<head>
<title>Conversion Test</title>
<script type=”text/javascript”>
// following gives expected results
// var penX = 1;
// var penY = 1;
// uncomment above and comment out below to see expected results
// following give un-expected results ???
var penX = 10;
var penY = 10;
function PlotPoint(x,y,w,h) {
alert(‘x,y,w,h: ‘+x+’,’+y+’,’+w+’,’+h); }
function _HLine(x,y,w) {
w = w+penY-1; alert(w);
return PlotPoint(x,y,w,this.penY); }
function _VLine(x,y,h) {
h = h+penX-1; alert(h);
return PlotPoint(x,y,this.penX,h); }
</script>
</head>
<body>
<button onClick=”_HLine(100,200,30)”>HLine</button>Expect 30 then 100,200,30,1<br />
<button onClick=”_VLine(100,200,40)”>VLine</button>Expect 40 then 100,200,1,40
</body>
</html>
Anyone have any idea what I’m doing wrong?
I have also tried:
w = parseInt(w)+penY-1; alert(w);
and
w = Number(w)+penY-1; alert(w);
and
w = (w*1)+penY-1; alert(w);
and
w = (+w)+penY-1; alert(w);
all with similar results. Also happens on h= … attempts.
For some reason the values are being concatenated rather than summed when penX and/or penY are not equal to 1.
?