+ 1
I need help on javascript
Javascipt has been giving me some errors lately like "unexpected reserved word" ..... Whenever I use something like this .. class Drop{} https://code.sololearn.com/WPnefInImvB2/?ref=app
2 Answers
0
class Drop {
constructor(xPosition, yPosition, dropSpeed, dropWidth, dropHeight) {
this.xPosition = xPosition;
this.yPosition = yPosition;
this.dropSpeed = dropSpeed;
this.dropWidth = dropWidth;
this.dropHeight = dropHeight;
this.element;
requestAnimationFrame(makeItRain);
}
show() {
this.element = document.createElement("div");
this.element.className += "rainDrop";
this.element.style.top = this.yPosition + "px";
this.element.style.left = this.xPosition + "px";
this.element.style.width = this.dropWidth + "px";
this.element.style.height = this.dropHeight + "px";
let el = document.getElementById("drops-section"); el.appendChild(this.element);
}
fall() {
const makeItRain = () => {
this.yPosition = this.yPosition + this.dropSpeed;
this.element.style.top = this.yPosition +"px";
if(this.yPosition < window.innerHeight) {
requestAnimationFrame(makeItRain);
} else {
this.yPosition = -10;
requestAnimationFrame(makeItRain);
}
}
}
}
this is your js intended.
the code now doesn't throw an error but I don't see anything happen... đ€·ââïž
->the "requestAnimationFrame" in the end at the bottom was not in any function so I put it into the constructor...
+ 3
you should post an exemple here, that would help to find the problem...