Go Back
Lesson 4 || simulated ball objects
Getting Started
- make a new repl html, css, js project
- copy the lesson 4
index.html, script.js, and style.css code into the repl
- hit the spacebar. what happens?
- hit ctrl-f and search for "var balls" and read the comments about it
- ctrl-f search "function initBall()" and read the comments
- inside the initBall function, change black to red, what happens?
- now change it to inputColor with no "" marks what happens?
Instantiating Custom Ball Objects
- ctrl-f for "function control"
- inside the control function, change pink to orange. what happens?
- go back to the initBall function definition, and add inputRadius as an input
- in the initBall function definition, change "radius : 10" to "radius : inputRadius"
- hit the spacebar, if balls arent popping up anymore, it means something is broken (fix it!)
- make the spacebar initialize a blue ball of radius 15
- make the w key initialize a red ball of radius 7
- make the e key initialize a yellow ball of radius 12
- bonus : make the r key destroy balls (hint - there is a helpful function in the code)
Wrapping up
- publish the lesson as a website on github pages (see lesson 2 instructions)