/    Sign up×
Community /Pin to ProfileBookmark

Conversion question …

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>
[/code]

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.
?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERauthorMar 24.2008 — Never mind, must be a cache problem.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...