user2028943 user2028943 - 5 months ago 6
HTML Question

A simple Canvas beyond my mind

<html>
<head>
<script>
function draw() {
var canvas = document.getElementById('draw');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
for (i=0,i<=700,i+=10){
ctx.beginPath();
ctx.moveTo(i,700-i);
ctx.lineTo(700-i,i);
ctx.stroke();
}
} else {
document.write("Hey idiot, whhich idiot browser you are using? No IE clan here!");
}
}
</script>
</head>
<body onload="draw();">
<canvas id="draw" width="700" height="700"></canvas>
</body></html>


Can anyone tell me what the problem is that this simple code is not working? .............................

Answer

Because your for loop is using commas, it needs semicolons:

for (i=0;i<=700;i+=10){

Also this is not OK:

document.write("Hey idiot, whhich idiot browser you are using? No IE clan here!");

Don't insult your users!