wwb00
  • wwb00
This won't be answered in CS. I have been writing some HTML canvas code in order to make a landscape. The code will not execute properly. What is my syntax error? Thanks, Benjamin var canvas = document.getElementById("mycanvas"); var ctx = canvas.getContext("2d"); var llocation = 600; var length = 360; var linewidth = 2; var testInt = length/(linewidth*2); var wColour = "#994c00"; for(i=0;i
Mathematics
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Compassionate
  • Compassionate
for(i=0;i
wwb00
  • wwb00
I'll try it.
wwb00
  • wwb00
some code got cut off. wait a sec.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

wwb00
  • wwb00
ctx.beginPath(); ctx.strokeStyle = wColour; ctx.lineWidth = linewidth; ctx.rect(llocation,300,length,250); ctx.stroke(); ctx.closePath(); var llocation = llocation + linewidth; var length = length - (linewidth*2); }
wwb00
  • wwb00
It's still not working.
Compassionate
  • Compassionate
No need for the { attached to the end. Try spacing it
wwb00
  • wwb00
Ok
Compassionate
  • Compassionate
for(i=0;i
wwb00
  • wwb00
Still did'nt fix.
wwb00
  • wwb00
Ill post all of my files.
Compassionate
  • Compassionate
Hmm... @dan815 @goformit100 @mathmale
wwb00
  • wwb00
1 Attachment
wwb00
  • wwb00
It won't let me post the other because of "forbidden" script
Compassionate
  • Compassionate
You should try asking this question on Yahoo Answers
wwb00
  • wwb00
I am.
wwb00
  • wwb00
And stack overflow.
anonymous
  • anonymous
Have you got any HTML to go with this? Saves me the trouble of making some to fit your script.
wwb00
  • wwb00
I do, but it won't let me post it.
anonymous
  • anonymous
Also, this is unnecessary: if(isEven(i)==true) { var wColour = "#994c00"; } else if(isEven(i)==false){ var wColour = "#B87333"; } There's no point evaluating isEven(i) == false because if you've already found that it's true then this must be false. Just get rid of "if(isEven(i)==false)"
wwb00
  • wwb00
Canvas

Canvas Practice

House

Your browser does not support the canvas app

anonymous
  • anonymous
Thanks. Is your isEven function defined elsewhere? No need to post it if it is, just checking it does actually exist.
wwb00
  • wwb00
It works now!!!
wwb00
  • wwb00
Thank you all!!!
wwb00
  • wwb00
I can't give two best responses...
wwb00
  • wwb00
sorry Compassionate
anonymous
  • anonymous
I was going to say, this code is working fine for me in JSFiddle: https://jsfiddle.net/4rhuf2kd/ For future reference, browser developing tools help massively when debugging JS. In Chrome, press F12 and you'll get the dev panel at the bottom. View the console and see what errors are there when you view your site, for me it said "Uncaught ReferenceError: isEven is not defined".
wwb00
  • wwb00
Thanks!
wwb00
  • wwb00
I have another problem now.
wwb00
  • wwb00
This code won't run in a function.
wwb00
  • wwb00
function drawHouse(){ for(i=0;i
wwb00
  • wwb00
var canvas = document.getElementById("mycanvas"); var ctx = canvas.getContext("2d"); var llocation = 600; var length = 360; var linewidth = 2; var testInt = length/(linewidth*2); var wColour = "#994c00"; function drawBackground(){ ctx.beginPath(); ctx.strokeStyle = "#3e9aff"; ctx.lineWidth = 10; ctx.rect(0,0,1000,600); ctx.stroke(); ctx.fillStyle = "#3e9aff"; ctx.fill(); ctx.closePath(); } function drawHouse(){ for(i=0;i
wwb00
  • wwb00
1 Attachment
wwb00
  • wwb00
There is nothing wrong in the terminal.
anonymous
  • anonymous
Just curious, why do you define each function then run them straight away? Might as well save yourself the declaration and just have one long block of code - unless you need to call them specifically elsewhere or you've been asked to do it this way specifically.
wwb00
  • wwb00
I wanted to have a functions reference, then a code that runs in a simplified manner. If this were to work, I would make local variables for the function.
anonymous
  • anonymous
Okay, I understand. What exactly are you expecting this code to do? It's showing a blue rectangle on top of a green one for me.
wwb00
  • wwb00
That's the background. It's to make a landscape.
wwb00
  • wwb00
The house is not displaying
okdutchman7
  • okdutchman7
Could please post this in Computer Science?
wwb00
  • wwb00
There are very few people on that section. Thank you tom982
anonymous
  • anonymous
Give me a second, I've given up with JSFiddle, going local now.
wwb00
  • wwb00
Ok
wwb00
  • wwb00
The house works perfectly not as a function.
wwb00
  • wwb00
I just got a tip from another section that it may be a scope issue with wColour
wwb00
  • wwb00
I fixed the scope, but it still won't draw the obj.
wwb00
  • wwb00
function drawHouse(){ var wColour = "#994c00"; function isEven(value) { if (value%2 == 0) return true; else return false; } alert(wColour); for(i=0;i
wwb00
  • wwb00
remove alert(wColour) it was for diagnostic purposes.
wwb00
  • wwb00
I fixed it. All the variables had the wrong scope!
wwb00
  • wwb00
Thanks so much!
wwb00
  • wwb00
function drawHouse(){ var wColour = "#994c00"; var llocation = 600; var length = 360; var linewidth = 2; var testInt = length/(linewidth*2); function isEven(value) { if (value%2 == 0) return true; else return false; } alert(wColour); for(i=0;i
anonymous
  • anonymous
Great, this was driving me mad.
wwb00
  • wwb00
I gave you the code you you can see it work. As we both have wanted.
anonymous
  • anonymous
Ah I see the problem now, and sorry but your fix isn't very tidy. In Javascript, if you want to access a variable outside the scope of the function you have to make sure you don't use 'var'. Simply removing var from the variables you used in drawHouse() fixes this: https://jsfiddle.net/z0ranjdh/

Looking for something else?

Not the answer you are looking for? Search for more explanations.