Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Samuel Altarac
4,961 PointsI need help with my code
can someone help me with my javascript please? My question is on line 45 of http://cdpn.io/LrBcD
Thanks :)
2 Answers
Patrick Metcalfe
Courses Plus Student 7,563 PointsHey, So I took a look at your code and I believe I found where you made your mistake. Yes when you instantiate your blocks each as a different and random x, but having a random x means absolutely nothing. Your equation is x=Sin(0.01*y)*100 And I think you mixed up the in/dependent variables. Your equation is in the form x=f(y) but in math class usually you see it as y=f(x). So setting a random x is meaningless because whenever you call move() it changes x(overrides your random value with a non random value). x(sub)n is not dependent on x(sub)(n-1) so x_0(your initial randomness x) in no way alters x_1. Same Equation=Same Path. If you want to change the paths so that they start in different places then you can use something like this. Make a variable like xInitial that gets set to a random number upon instantiation, and change the equation to something like x=100sin(0.01y)+xInitial This causes each block to be shifted right depending on that original xInitial value. And if each has a different equation then they all have different paths(though they are similar). I hope this makes sense, and btw were you trying to do snow or just messing around, idk it just made me think of snow falling. Good Luck!
Patrick Metcalfe
P.S. I would recommend putting more specific titles to your posts. It will help guide the right people to your question. "Help with code" could require anyone from a ruby dev to a fortran dev to a html guy, being specific will speed up answer time!
Samuel Altarac
4,961 PointsThank you patrick for your time and patience. I will follow your advice.
Indeed I was trying to make a snow program after having been inspired by what others have done in code pen and on code player.com. Im just a beginner so as you can see my code is all buggy and very simple...