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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Color Game</title>
    <link rel="stylesheet" href="colorGame.css">
    <link href="https://fonts.googleapis.com/css?family=Fira+Sans|Montserrat" rel="stylesheet">
    <!-- favicon -->
    <link href="data:image/x-icon;base64,AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+4z/L/pMLv//j6/f///////v7//6vG8P+lwu//5u76/3ek5/+70fP///////7+/v+wyvH/daLn/9Hg9////////////////////////////////////////////////////////////////////////////////////////////1SM4f8kbNn/8PX8///////H2vX/CFnU/4yy6v/W4/j/ClvU/4St6f//////y9z2/xVi1v9QiuD/9Pf9////////////////////////////////////////////////////////////////////////////////////////////VIzh/yRs2f/w9fz/9Pf9/z9+3f9Egd7/8/f9/9bj+P8KW9T/hK3p/+7z+/8ob9n/LXLa//D0/P////////////////////////////////////////////////////////////////////////////////////////////////9UjOH/JGzZ/87e9v+Bqun/CVrU/8zc9v//////1uP4/wpb1P9+qej/ZZfk/xdj1v/J2/X//////////////////////////////////////////////////////////////////////////////////////////////////////1SM4f8kbNn/jrPr/zB02/8RX9X/e6bo//X4/f/W4/j/ClvU/2+e5v8faNj/oL/u////////////////////////////////////////////////////////////////////////////////////////////////////////////VIzh/yRs2f/w9fz/+vz+/6zH8P8EVtP/p8Tv/9bj+P8KW9T/cqDm/yRs2f9ek+P/+fv+//////////////////////////////////////////////////////////////////////////////////////////////////////9UjOH/JGzZ//D1/P///////v7//xJf1f9vnuX/1uP4/wpb1P+ErOn/nb3t/wdY1P+cvO3//v7//////////////////////////////////////////////////////////////////////////////////////////////////1SM4f8kbNn/8PX8//7+///J2/X/BFbT/5G17P/W4/j/ClvU/4St6f/5+/7/RoLe/xZi1v/e6fn/////////////////////////////////////////////////////////////////////////////////////////////////VIzh/yRs2f+au+3/RYLe/xdj1v9bkeL/7/T8/9bk+P8MXNX/ha3q///////W4/f/GmXX/0iE3//1+P3///////////////////////////////////////////////////////////////////////////////////////////+70fP/p8Tv/8fZ9f+jwe//xtn1/8nMz/+Ojo7/vcDG/77S8v/f6fn///////7+/v/P3/b/wNT0//T4/f/////////////////////////////////////////////////////////////////////////////////////////////////////////////////39/f/aWlp/9jY2P9ycnL/29vb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////v7+/9LS0v/CwsL/9/f3//r6+v9oaGj/vr6+/2xsbP/f39//7Ozs/729vf/j4+P//v7+//////////////////////////////////////////////////////////////////////////////////////////////////////+7u7v/f39//6CgoP+JiYn//v7+/+Hh4f+pqan/29vb//n5+f9mZmb/qqqq/2xsbP/h4eH//////////////////////////////////////////////////////////////////////////////////////////////////////6urq/+ampr/0NDQ/3d3d//9/f3/rMfw/9nl+P+zzPH/9vb2/2RkZP/c3Nz/eXl5/9jY2P//////////////////////////////////////////////////////////////////////////////////////////////////////9/f3/5mZmf+Li4v/5OTk/+Hr+f+Msuv/ydv1/42y6//u9Pz/ysrK/4aGhv+0tLT//Pz8/////////////////////////////////////////////////////////////////////////////////////////////////////////////Pz8//j4+P/4+v3/XJHi/+Xt+v//////irHq/7nQ8//+/v7/9fX1//7+/v///////////////////////////////////////////////////////////////////////////////////////////////////////////9nZ2f9ra2v/b29v/7e3t//k7fr/bp3l/6C/7v+xyvH//Pz8/42Njf91dXX/eHh4//Dw8P//////////////////////////////////////////////////////////////////////////////////////////////////////o6Oj/7a2tv/t7e3/bW1t//b4/P/U4vf/4Or5/+nw+//z8/P/ZmZm//b29v+FhYX/09PT///////////////////////////////////////////////////////////////////////////////////////////////////////g4OD/eXl5/3l5ef+/v7///Pz8/6Kiov+FhYX/vr6+//39/f+Xl5f/gYGB/4WFhf/z8/P////////////////////////////////////////////////////////////////////////////////////////////////////////////4+Pj/9PT0///////Ozs7/hoaG/97e3v9tbW3/6+vr//39/f/w8PD//f39/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+fn5/9vb2//mpqa/3d3d//09PT//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+Dg4P/IyMj/7e3t////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
        rel="icon" type="image/x-icon" />
    <!-- favicon end -->
</head>

<body>
    <h1 class="first-header" id="header-one">The Great
        <br>
        <!--Line Break-->
        <span id="colorDisplay"></span>
        <br> Color Game</h1>
    <div id="stripe">
        <button class="reset-btn" id="reset">New Colors</button>
        <span id="message"></span>
        <button class="mode">Easy</button>
        <button class="mode selected">Hard</button>
    </div>
    <div id="container">
        <div class="square"></div>
        <div class="square"></div>
        <div class="square"></div>
        <div class="square"></div>
        <div class="square"></div>
        <div class="square"></div>
    </div>

    <footer id="footer">
        <h1 id="footer-message"></h1>
    </footer>
    <script src="colorGame.js"></script>
</body>

</html>
              
            
!

CSS

              
                body {
    background-color: #232323;
    margin: 0;
    font-family: "sans-serif", "Montserrat", "Fira Sans";
  overflow-x:hidden;
}

.square {
    width: 30%;
    background: purple;
    padding-bottom: 30%;
    float: left;
    margin: 1.66%;
    border-radius: 43%;
    transition: background 0.6s;
    /*    these two are browser prefixes to make it browser friendly to safari and firefox*/
    -webkit-transition: background 0.6s;
    -moz-transition: background 0.6s;
}

#container {
    margin: 20px auto;
    overflow: auto;
    /*    same size on either size*/
    max-width: 600px;
}

h1 {
    color: white;
    margin: 0;
    text-align: center;
    line-height: 1.1;
    padding: 20px 0;
    text-transform: uppercase;
}

#message {
    display: inline-block;
    width: 20%;
}

#stripe {
    background-color: white;
    height: 30px;
    text-align: center;
    color: black;
}

#stripe span {
    color: black;
}

.selected {
    color: white;
    background: steelblue;
}

#colorDisplay {
    font-size: 200%;
    /*    200 percent of h1 fonttag*/
    text-transform: uppercase;
}

button {
    font-family: "sans-serif", "Montserrat", "Fira Sans";
    font-weight: 700;
    color: steelblue;
    border: none;
    background: none;
    text-transform: uppercase;
    height: 100%;
    letter-spacing: 1px;
    font-size: inherit;
    transition: all .5s;
    /*    these two are browser prefixes to make it browser friendly to safari and firefox*/
    -webkit-transition: all .5s;
    -moz-transition: all .5s;
    outline: none;
}

button:hover {
    /*    hoving over this char creates these effects*/
    color: white;
    background: steelblue;
}

footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    min-height: 76px;
    background-color: steelblue;
}

#footer-message {}

/*
MEDIA QUERIES
*/

@media only screen and (max-width: 600PX) {
    #colorDisplay {
        font: size 114%;
    }
    #colorDisplay {
        font-size: 1em;
    }
    #message {
        position: relative;
        top: -1px;
    }
}

@media only screen and (max-width: 360px) {
    #header-one {
        font-size: 1.2em;
    }
}

@media only screen and (max-width: 468px) {
    #message {
        display: none;
        width: 10px;
    }
    .reset-btn {
        margin-right: 50px;
    }
}

@media only screen and (max-width: 320px) {
    .reset-btn {
        margin-right: 12px;
    }
    #stripe{
        font-size: 12px;
    }
}
@media only screen and (max-width: 280px) {
    .reset-btn {
        margin-right: 10px;
    }
    #stripe{
        font-size: 12px;
    }
}

/* HEIGHT */

@media only screen and (max-height: 490px) {
    #container {
        /* max-width: 280px !important; */
    }
}

/* height and width*/

@media only screen and (max-height: 710px) and (min-width: 220px) {
    #container {
        max-width: 420px;
    }
}
    /* HEIGHT inside MaxH710 <-> MinWidth 220px */
    @media only screen and (min-height: 657px) and (max-height: 710px) {
        #container {
            max-width: 480px;
        }
    }
    @media only screen and (min-height: 562px) and (max-height: 657px) {
        #container {
            max-width: 300px;
        }
    }
    @media only screen and (max-height: 520px) {
        #footer-message {
            padding-top: 0;
        }
        #footer {
            height: 30px;
            min-height: 0;
            padding: 5px;
        }
    }
    @media only screen and (min-height: 445px) and (max-height: 562px) {
        #container {
            max-width: 250px;
        }
        #colorDisplay {
            font-size: 150%;
        }
    }
    @media only screen and (min-height: 300px) and (max-height: 445px) {
        #container {
            max-width: 280px;
        }
        h1 {
            font-size: 1.5em;
            padding: 5px;
        }
    }

              
            
!

JS

              
                var numberSqrs = 6;
var colors = [];
var squares = document.querySelectorAll(".square");
var colorDisplay = document.querySelector("#colorDisplay");
var footerMessageDisplay = document.querySelector("#footer-message");
var messageDisplay = document.querySelector("#message");
var pickedColor = pickColor();
var resetButton = document.getElementById("reset");
var h1 = document.querySelector(".first-header");
var footer = document.getElementById("footer");
var modeButtons = document.querySelectorAll(".mode");

init();

function init() {
    //mode buttons event listeners
    for (var x = 0; x < modeButtons.length; x++) {
        modeButtons[x].addEventListener("click", function () {
            modeButtons[0].classList.remove("selected");
            modeButtons[1].classList.remove("selected");
            this.classList.add("selected");
            this.textContent === "Easy" ? numberSqrs = 3 : numberSqrs = 6;
            reset();
        });
    }
    //Add Events to each Square
    for (var i = 0; i < squares.length; i++) {
        //add click listeners to squares
        squares[i].addEventListener("click", function () {
            //grab color of clicked square
            var clickedColor = this.style.backgroundColor;
            //compare color to pickedColor
            if (clickedColor === pickedColor) {
                messageDisplay.textContent = "Correct!"
                footerMessageDisplay.textContent = "Correct!"
                h1.style.backgroundColor = pickedColor;
                footer.style.backgroundColor = pickedColor;
                console.log(footer.style.backgroundColor);
                changedColors(clickedColor);
                resetButton.textContent = "Play Again?";
            } else {
                this.style.backgroundColor = "#232323";
                messageDisplay.textContent = "Try Again!";
                footerMessageDisplay.textContent = "Try Again!";
            }
        });
    }

    resetButton.addEventListener("click", function () {
        reset();
    });

    reset();
}

//Main
for (var i = 0; i < squares.length; i++) {
    //add click listeners to squares
    squares[i].addEventListener("click", function () {
        //grab color of clicked square
        var clickedColor = this.style.backgroundColor;
        //compare color to pickedColor
        if (clickedColor === pickedColor) {
            messageDisplay.textContent = "Correct!"
            h1.style.backgroundColor = pickedColor;
            footer.style.backgroundColor = pickedColor;
            changedColors(clickedColor);
            resetButton.textContent = "Play Again?";
        } else {
            this.style.backgroundColor = "#232323";
            messageDisplay.textContent = "Try Again!";
        }
    })
}
//End Main


function reset() {
    colors = generateRandomColors(numberSqrs);
    //pick a new random color from array
    pickedColor = pickColor();

    //change colorDisplay to match picked color
    colorDisplay.textContent = pickedColor;
    messageDisplay.textContent = "";
    footerMessageDisplay.textContent = "";
    resetButton.textContent = "New Colors";
    //change colors of squares
    for (var i = 0; i < squares.length; i++) {
        if (colors[i]) {
            squares[i].style.display = "block";
            squares[i].style.backgroundColor = colors[i];
        } else {
            squares[i].style.display = "none";
        }
    }
    h1.style.backgroundColor = "steelblue";
    footer.style.backgroundColor = "steelblue";
}

function changedColors(color) {
    //loops through all squares
    for (var i = 0; i < squares.length; i++) {
        //change each color to match given color
        squares[i].style.backgroundColor = color;
    }
}

function pickColor() {
    //pick random whole number use Math.floor(Math.random());
    var random = Math.floor(Math.random() * colors.length);
    return colors[random];
}

function generateRandomColors(num) {
    //make an array
    var arr = [];
    //repeat num times
    for (var i = 0; i < num; i++) {
        //get random color and push into array
        arr[i] = randomColor();
    }
    //return array
    return arr;
}

function randomColor() {
    //pick a red from 0-255
    var r = Math.floor(Math.random() * 256);
    //pick a green from 0-255
    var g = Math.floor(Math.random() * 256);
    //pick a blue from 0-255
    var b = Math.floor(Math.random() * 256);
    return "rgb(" + r + ", " + g + ", " + b + ")";
}
              
            
!
999px

Console