Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Etch A Sketch - The Odin Project</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <center>
            <h3>Etch-a-Sketch</h3>
            <input type="button" class="button clearScreen" value="Clear Screen">
            <input type="button" class="button newSize" value="New Grid Size">
            <input type="button" class="button rainBow" value="Rainbow Mode">
        </center>
        <div id="container"></div>
        <script src="script.js"></script>
    </body>
</html>
              
            
!

CSS

              
                .row {
    width: auto;
    background: #210d94;
}

#container {
    width: 640px;
    height: 640px;
    margin-top: 50px;
    margin-bottom: 100px;
    margin-left: auto;
    margin-right: auto; 
    background: #56abd3;
    border: 15px solid;
    border-radius: 20px;
}

body {
    background-color: rgb(18, 161, 73);
}

h1 {
    margin-top: 50xp;
    font-family: "Helvetica";
}

.square {
    margin: 0px;
    display: inline-block;
    float: left;
    background: #ffffff;
}

.button {
    background-color: black;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 8px;
}

.button:hover {
    background-color: #555555;
}

.button:active {
    background-color: #555555;
    box-shadow: 0 5px #666;
    transform: translateY(10px);
}
              
            
!

JS

              
                function createGrid(dim) {
    var $row = $("<div />", {
        class: 'row'
    });
    var $square = $("<div />", {
        class: 'square'
    });

    // add columns to initial row
    for (var i=0; i<dim; i++) {
        $row.append($square.clone());
    }

    // copy row appropriate num times
    for (var i=0; i<dim; i++) {
        $("#container").append($row.clone());
    }

    // fit rows to container
    $(".square").width(640/dim);
    $(".square").height(640/dim);
}

function clearScreen() {
    $(".square").remove();
}

function newSize() {
    var new_dim = prompt("How many cells would you like per side? Choose an integer between 2 and 64")
    if(new_dim > 64) {
        alert("You choose an integer greater than 64. The grid length is being set to 64");
        new_dim = 64;
    }

    clearScreen();

    createGrid(new_dim);

    $(".square").mouseover(function() {
        $(this).css("background-color", "black");
    });
    return new_dim;
}

function olKamalak() {
    var belgilar = '0123456789ABCDEF';
    var rang = '#';
    for (var i=0; i<6; i++) {
        rang += belgilar[Math.floor(Math.random() * 16)];
    }
    return rang;
}

$(document).ready(function() {
    var n = 16;
    createGrid(n);

    // change square color to black upon mouse over
    $(".square").mouseover(function() {
        $(this).css("background-color", "black");
    });

    // If Clear Screen is clicked
    $(".clearScreen").click(function() {
        clearScreen();
        createGrid(n);
        $(".square").mouseover(function() {
            $(this).css("background-color", "black");
        });
    });

    $(".newSize").click(function() {
        n = newSize();
    });

    // If rainbow is clicked
    $(".rainBow").click(function() {
        $(".square").mouseover(function() {
            $(this).css("background-color", olKamalak());
        });
    });

});
              
            
!
999px

Console