GithubHelp home page GithubHelp logo

etch_a_sketch's Introduction

General Assembly Logo

Etch-a-sketch

Topics

  • selecting DOM elements with query selectors
  • attaching events to DOM elements with addEventListener
  • looping

Instructions

We're going to build a virtual etch-a-sketch in the browser! Explore the existing html, css, and js code in the etch_a_sketch directory.

Final product

You will primarily be adding code to index.js, but if you think something you need is missing from index.html or style.css, you can add it.

Step 1: making 1 pixel work

Just One Pixel

Note that there's already 1 pixel in the screen div. It's already styled to look like a pixel. Eventually, we will fill the screen up with pixels, but first, we should make just this 1 pixel function correctly. Our goal is to make this pixel turn black when the mouse hovers over it.

  • Tools you already have that will help: addEventListener, <anyDomElement>.classList.add
  • Tools you will have to research: the mouseenter event
  • Tip: check out the .colored-in class in the style.css

Step 2: filling the screen with pixels

We want a bunch of tiny little pixels that behave just like our original. Let's fill the grey screen div up with them. It is totally ok if they do not fill the space perfectly, or if there are any awkward little gaps of grey. A hard-coded guesstimate of how many pixels should fit in the box is fine!

  • Tools: for loops, document.createElement, <anyDomElement>.classList.add, <anyDomElement>.append

Step 3: making all the pixels function like our original

Let's replicate the behavior of our original pixel for the entire bunch. Warning: if you find yourself writing several thousand addEventListeners, you are doing it wrong!

  • Tools: everything from Step 1, using the event parameter and event.target inside your callback function, document.querySelectorAll

Step 4: the clear screen button

Attach a click listener to the Clear Screen button. When clicked, this button should reset all the pixels to white.

  • Tools: document.querySelectorAll, <anyDomElement>.classList.remove

Step 5: celebrate your success! ๐Ÿฐ ๐ŸŽ‰ ๐ŸŽ

Play with your new etch-a-sketch!

etch_a_sketch's People

Contributors

h64 avatar apexbortz avatar weston-bailey 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.