Giter Site home page Giter Site logo

d-mbithi / js-exercise Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ramenhog/js-exercise

0.0 2.0 0.0 10 KB

A beginner javascripting exercise for developers with an understanding of HTML/CSS and programming fundamentals, but needing a practical application.

HTML 85.31% JavaScript 14.69%

js-exercise's Introduction

Given an empty HTML document, use raw JS (and optionally some CSS) to...
Reminder: Inspection tools are your friend.

###Set 1

  1. create and insert an empty div on the page. It should have
  • width and height
  • positioning
  • top and left coordinates
  • background color expressed as rgba
  1. write a function "buildBox" that creates and inserts that div on the page and assigns it to a variable.
  2. write a function "randInRange" that generates a random integer, given a range of possible values (min & max).
  3. write a function "setStyles" that accepts an element and sets all numerical CSS properties to random values within logically derived ranges.

###Set 2 5. using setTimeout, run setStyles on the box once every second, continuously. Ok, then turn it off. 6. create a new loop that smoothly animates the position of the box, moving it 60 times per second. 1px horizontal and 1px vertical is a good velocity to start. 7. set the initial velocity to be randomly generated, within reasonable bounds. 8. update the animation such that the box changes direction predictably when it touches the edge of the viewport. 9. if you haven't already, set the velocity to change randomly (within acceptible bounds!) when it touches the edge of the viewport.

###Set 3 10. update buildBox to be a constructor for a new Box Object prototype. It should have as properties

  • a styled HTML element that exists in the DOM
  • its position (x & y)
  • its size (width & height)
  • its velocity (x & y)
  1. write a method "bounce" to handle the speed and direction changes.
  2. attach "bounce" to click events on the Box, so it changes direction and speed when clicked upon.
  3. using a loop and an array, create 100 Boxes and store them for later reference.

js-exercise's People

Contributors

elisewei avatar

Watchers

James Cloos avatar Dennis Mbithi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.