Javascript Rock Dodger

JavaScript Rock Dodger

Use JavaScript to build a rock-dodging game

Explain how window.requestAnimationFrame() is used to animate movement on a page

Explain how to use setInterval()

Show off your JavaScript know-how

Instructions

You did it — you've made it to the end of the introductory JavaScript
curriculum. You've learned how to write JavaScript and how to use JavaScript to
manipulate the DOM. Now, only this lab stands between you and freedom the
end of this course!

So that we don't catch you off-guard, know that this project is meant to be
difficult. We're really testing the limits of what we've learned so far. But
know that we've solved the lab using only things that we've taught — well,
mostly. There are two things (which we've partially implemented for you) that
you should know about.

window.requestAnimationFrame()

This function tells the browser that we want to animate some change on the page.
We'll use it in this lab for animating the movement of rocks and the dodger.

If we call move(el) with a valid DOM element, window.requestAnimationFrame()
will be called with the function step, which moves the el down the page in
two-pixel increments until it's been moved 200 pixels. Pretty easy, right?

(Note that we can pass step to window.requestAnimationFrame()inside of
step. This is a nifty feature of JavaScript (and other languages) called
recursion. Don't
worry if this concept makes your head spin a bit — that feeling is normal. For
now, know that we can use window.requestAnimationFrame() as demonstrated
above.)

setInterval()

setInterval()
takes two arguments: a callback, and an interval in milliseconds. We can use it
like so:

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.

Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.