CODING PRACTICE 1 Color Picker

 Color Picker

In this assignment, let's build a Color Picker by applying the concepts we learned till now.

Refer to the below image.

color-switcher

Instructions:

  • The HTML container element that is wrapping all the HTML elements should have the id 
    colorPickerContainer
  • The HTML 
    span
     element should have the id 
    selectedColorHexCode
  • The HTML 
    button
     element with text as #e0e0e0 should have the id 
    button1
  • The HTML 
    button
     element with text as #6fcf97 should have the id 
    button2
  • The HTML 
    button
     element with text as #56ccf2 should have the id 
    button3
  • The HTML 
    button
     element with text as #bb6bd9 should have the id 
    button4
Warning
Do not edit or remove the ids of the HTML 
button
 elements in the prefilled code.

By following the above instructions, achieve the given functionality.

  • The background color of the page and the Hex Code value in the HTML 
    span
     element should change when the HTML 
    button
     element is clicked.
  • The background color of the page and the background color of the clicked HTML 
    button
     element should be the same.
  • The text in the clicked HTML 
    button
     element and the text in the HTML 
    span
     element should be the same.
Note
  • Try to achieve the design as close as possible.
  • Apply the styles and functionality to the given HTML prefilled code.

Resources

CSS Colors used:

#e0e0e0
#6fcf97
#56ccf2
#bb6bd9
#222222
#49a6e9

CSS Font families used:

  • Open Sans

Concepts Review

Want to quickly review some of the concepts you’ve been learning?

Take a look at the Cheat Sheets.



<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous" /> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> </head> <body> <div id="colorPickerContainer" class="d-flex flex-column justify-content-center"> <h1>Color Picker</h1> <div> <button class="button btn1" onclick="colorOne()" id="button1">#e0e0e0</button> <button class="button btn2" onclick="colortwo()" id="button2">#6fcf97</button> <button class="button btn3" onclick="colorthree()" id="button3">#56ccf2</button> <button class="button btn4" onclick="colorfour()" id="button4">#bb6bd9</button> </div> <p class="Background_Color mt-3 mb-3">Background Color : <span id="selectedColorHexCode">#fffff</span></p> <p>Try clicking on one of the colors above to change the background color of this page!</p> </div> </body> </html>





@import url('https://fonts.googleapis.com/css2?family=Bree+Serif&family=Caveat:wght@400;700&family=Lobster&family=Monoton&family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&family=Playfair+Display+SC:ital,wght@0,400;0,700;1,700&family=Playfair+Display:ital,wght@0,400;0,700;1,700&family=Roboto:ital,wght@0,400;0,700;1,400;1,700&family=Source+Sans+Pro:ital,wght@0,400;0,700;1,700&family=Work+Sans:ital,wght@0,400;0,700;1,700&display=swap');


#colorPickerContainer {

    height: 100vh;

    text-align: center;

}


h1 {

    font-weight: 900;

    font-size: 35px;

    margin-bottom: 20px;

}


.button {

    height: 90px;

    width: 90px;

    border-radius: 20px;

    border-style: solid;

    border-width: 2px;

    font-size: 12px;

}


.btn1 {

    background-color: #e0e0e0;

}


.btn2 {

    background-color: #6fcf97;

}


.btn3 {

    background-color: #56ccf2;

}


.btn4 {

    background-color: #bb6bd9;

}


.Background_Color {

    background-color: #222222;

    color: #ffffff;

    padding: 10px;

    font-size: 22px;

    font-weight: 600;

    border-radius: 10px;


}


#selectedColorHexCode {

    color: #49a6e9;

}







let colorPickerContainer = document.getElementById("colorPickerContainer");

let selectedColorHexCode = document.getElementById("selectedColorHexCode");


function colorOne() {

    colorPickerContainer.style.backgroundColor = "#e0e0e0";

    selectedColorHexCode.textContent = "#e0e0e0";

}


function colortwo() {

    colorPickerContainer.style.backgroundColor = "#6fcf97";

    selectedColorHexCode.textContent = "#6fcf97";

}


function colorthree() {

    colorPickerContainer.style.backgroundColor = "#56ccf2";

    selectedColorHexCode.textContent = "#56ccf2";

}


function colorfour() {

    colorPickerContainer.style.backgroundColor = "#bb6bd9";

    selectedColorHexCode.textContent = "#bb6bd9";

}


Comments

Popular posts from this blog

CODING ASSIGNMENT 3 Library Management

CODING PRACTICE 11 Music Page

CCBP Static Website Coding Assignment 2 Solution | Yoga Page